Jump to content

Recommended Posts

Basically I have two tables like so.

 

TBL1

NAME (20 values)

 

TBL2

WEEK

aNAME

bNAME

 

Each week there is 5 different combos with aNAME and bNAME.  TBL2 names are the same names used in TBL1.

 

If for week one 10 of the 20 names are listed together.  (aNAME w/ bNAME)

 

All I want is to be able to display the other 10 names from TBL1 that weren't paired, below the list of users from TBL2

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/69987-comparing-data-on-two-tables/
Share on other sites

SELECT a.name FROM tbl1 a
WHERE a.name NOT IN
(SELECT namea FROM tbl2 WHERE week = 1)
AND a.name NOT IN
(SELECT nameb FROM tbl2 WHERE week = 1)

 

or, without subqueries,

SELECT a.name FROM tbl1 a
LEFT JOIN tbl2 b ON a.name = b.namea
LEFT JOIN tbl2 c ON a.name = c.nameb
WHERE b.namea IS NULL AND c.nameb IS NULL

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.