Jump to content

Comparing Data on two Tables


baddkar

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.