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 6151231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:44:27+00:00 2026-05-23T19:44:27+00:00

Im not sure how to explain this and im not use to SQL..this is

  • 0

Im not sure how to explain this and im not use to SQL..this is my query which isnt working

select * from ao_addrcodes 
JOIN a1_addrs on a1_addrid = ao_addrid left Join a2_name on a2_addrid = ao_addrid 
where ao_codeid = 'DJ' and 'E' and 'A'

Trying to get a list of people who are in the table ao_addrid and their ao_codeid is ‘DJ’ and ‘E’ and ‘A’

So Fred would be in the table 3 times. His a2_addrid would be the same but would his
ao_codeid would be different

Each person has multiple records if they have multiple ao_codeid ‘s

help?

EDIT

ao_codeid , a2_addrid

'DJ', '525'
'E', '525'
'A', '525'
'DJ', '52'
'A', '25'
'E', '25'

So from the above data i would only want to see the user 525 appear. Not 52 or 25.

I am using MySQL

  • 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-05-23T19:44:28+00:00Added an answer on May 23, 2026 at 7:44 pm

    If you’re using SQL Server, then your WHERE statement is incorrect:

    SELECT    *
    FROM      ao_addrcodes
    JOIN      a1_addrs ON a1_addrid = ao_addrid
    LEFT JOIN a2_name ON a2_addrid = ao_addrid 
    WHERE     ao_codeid IN('DJ', 'E', 'A')
    

    Or you could do it like this

    WHERE     ao_codeid = 'DJ'
    OR        ao_codeid = 'E'
    OR        ao_codeid = 'A'
    

    EDIT 1

    I would do something like this:

    --Create a CTE that counts eligible records
    WITH CodeCount AS
    (
        SELECT    ID, --this represents your 525 data
                  COUNT(*) AS CodeCount
        FROM      [your table]
        WHERE     code IN('DJ', 'E', 'A')
        GROUP BY  ID
    )
    
    SELECT        *
    FROM          [your table]
    INNER JOIN    CodeCount ON [your table].ID = CodeCount.ID
    WHERE         CodeCount = 3
    

    EDIT 2

    Since you edited your post to say you’re using MySQL, this would be my solution:

    SELECT    *
    FROM      ao_addrcodes
    JOIN      a1_addrs ON a1_addrid = ao_addrid
    LEFT JOIN a2_name ON a2_addrid = ao_addrid
    INNER JOIN (
                    SELECT       ID,
                    COUNT(*) AS  EligibleCount
                    FROM         ao_addrcodes
                    WHERE        ao_codeid IN('DJ', 'E', 'A')
                    GROUP BY     ID
                ) a ON a.ID = ao_addrcodes.ID
    WHERE         a.EligibleCount = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how to explain this probably, so I'll use an example. I
I'm not sure how to explain this. So here goes... I'm trying to fit
Not sure if I can explain this correctly, but I am trying to execute
I'm not sure exactly how to explain this, so I'll just start with an
I'm not sure how to best explain this, so this may be a bit
I'm not really sure how to explain this so here is a picture: Window
I'm not sure how to best explain this so I have linked to a
I am not very sure with the use of this [current context] in jquery.What
I'm not really sure how I can explain this, but here goes: I want
Here's the query that is being executed on SQL Server 2008: SELECT "dbo"."tblMainData"."recID" 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.