baddkar Posted September 20, 2007 Share Posted September 20, 2007 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 More sharing options...
Illusion Posted September 20, 2007 Share Posted September 20, 2007 Try this Select a.name from tbl1 as a,tbl2 as b where a.name !=b.aname OR a.name !=b.bname; Link to comment https://forums.phpfreaks.com/topic/69987-comparing-data-on-two-tables/#findComment-351565 Share on other sites More sharing options...
Barand Posted September 21, 2007 Share Posted September 21, 2007 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 Link to comment https://forums.phpfreaks.com/topic/69987-comparing-data-on-two-tables/#findComment-351951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.