Jump to content

SQL query help please...


khawaib

Recommended Posts

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

  • 2 weeks later...

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.