mrhenniger Posted December 29, 2008 Share Posted December 29, 2008 First time poster here. I have dabbled with MySQL via PHP. I have done queries across multiple tables using JOINs. Here is the problem I am currently considering. Table1... Serial - int OtherColumnA OtherColumnB ...the values for Serial in this table are unique. Table2... Serial - int StuffA StuffB ...there can be duplicate values for Serial (non-unique). I would like to create a MySQL query that will list all the values of Serial in Table1 which DON'T EXIST in Serial in Table2. I don't know enough about MySQL to solve the problem. Can anyone here help? Thanks in advance for any assistance you can provide. Regards, Mike Quote Link to comment https://forums.phpfreaks.com/topic/138685-query-over-two-tables/ Share on other sites More sharing options...
btherl Posted December 29, 2008 Share Posted December 29, 2008 This is the postgresql forum (and your topic will be moved over to the mysql forum shortly), but the answer is the same. SELECT * FROM t1 LEFT JOIN t2 USING (serial) This query will combine rows from t1 and t2, matching them up by the serial value. If there's no match, then t1.serial will be set but t2.serial will be null. So if you want all serials from t1 that aren't in t2 you just need to do this: SELECT * FROM t1 LEFT JOIN t2 USING (serial) WHERE t2.serial IS NULL Or "SELECT t1.serial" if you just need the serials. Quote Link to comment https://forums.phpfreaks.com/topic/138685-query-over-two-tables/#findComment-725089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.