Jump to content

Join question


Scotty2024

Recommended Posts

Hello. I'm trying to create a query to join on two tables.

 

Table1 has id and name. Table2 has userID and itemID.

 

Table1 id and table2 userID are the same. For a specific itemID I want to select all names from table1 where the userID in table2 does not exists.

 

For example, here is some test data.

 

Table1

1 Bill

2 Bob

3 Joe

 

Table2

1 1

2 1

3 2

 

If I wanted to get all names where the userID wasn't listed for itemID 1, it would return Joe. Similarly if I wanted to get all names where the userID wasn't listed for itemID 2, it would return Bob and Joe. Finally, if I wanted to get all names where the itemID was not equal to 1 or 2, it would return Bill, Bob, and Joe.

 

How do I join the two tables to do this? Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.