Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:08:13+00:00 2026-06-03T00:08:13+00:00

I need a SQL statement to extract those applicants from the database who have

  • 0

I need a SQL statement to extract those applicants from the database who have both the attachment tags. The belowq statement works fine if I want aaplicant who have either 7 or 8 as the attachment tag but i need applicant who have both these tags.

select distinct(a.id) from applicant a
join applicantdeployment ad on a.id = ad.applicantid
join ApplicantAttachment at on a.id = at.applicantid
where a.applicanttype = 'TCN/LN' and ad.groundlocation in (4,8,14) and ad.deploymentstatus =1
and ad.trainingdeploymentstatus = 6 and at.tag in (7,8)

For example from the below set I just want ids 7332,7451 and 7449 to show up.

ID      Tag

7328   8

7328   8

7332   8

7332   7

7337   7

7449   8

7449   7

7451   8

7453   7

7451   7

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:08:14+00:00Added an answer on June 3, 2026 at 12:08 am

    You could join to the ApplicationAttachment table twice to ensure that both tags are present. That way you would avoid the need for DISTINCT and GROUP BY.

    SELECT a.id
    FROM applicant a
    JOIN applicantdeployment ad ON a.id = ad.applicantid
    JOIN ApplicantAttachment at7 ON a.id = at7.applicantid AND at7.tag = 7
    JOIN ApplicantAttachment at8 ON a.id = at8.applicantid AND at8.tag = 8
    WHERE a.applicanttype = 'TCN/LN' 
    AND ad.groundlocation IN (4,8,14)
    AND ad.deploymentstatus = 1
    AND ad.trainingdeploymentstatus = 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Statement where i need to display the value from another
select max(Key) from MyTable with(nolock) I have this T-SQL statement but need to use
I an SQL SELECT statement I need to extract the name of two teams,
I have the following SQL Statement. I need to select the latest record for
I have a dynamic SQL statement I've created in a stored procedure. I need
Is it possible to extract sql statements from LINQ queries ? Say, I have
I need to extract data from a third party system (I have no influence
Afternoon All, I have a dropdown list which extracts data from my SQL database
A continuation from this question I need a SQL statement that returns the number
I need help converting this SQL statement, into EF4: Select Posts.PostID, Post, Comment from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.