khawaib Posted August 28, 2009 Share Posted August 28, 2009 Hi, I have two tables of data and I am trying to get the rows of one table that are not matching in other table. Not sure how to do that. For example: Table __a: id user1_id user2_id 1 5 7 Table __users: id username 5 a 6 b 7 c I need a query that should return me rwo 2 from Table 2 as it does not have matching row in table 1. I tried this but it does not return expected result: Code: $q = 'SELECT u.id, u.username FROM __users u '; $q .= 'LEFT JOIN __a a1 ON (u.id = a1.user1_id OR u.id = a1.user2_id) '; $q .= 'WHERE a1.user1_id = u.id OR a1.user2_id = u.id LIMIT 10'; Any help much appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/172338-sql-query-help-please/ Share on other sites More sharing options...
fenway Posted September 7, 2009 Share Posted September 7, 2009 You're missing the "IS NULL" condition in your where clause. Link to comment https://forums.phpfreaks.com/topic/172338-sql-query-help-please/#findComment-914134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.