Forums
This topic is locked
MySql Query
Posted 14 Dec 2005 11:34:26
1
has voted
14 Dec 2005 11:34:26 luca martino posted:
I have a db on MySQl 4, i'm trying a selection query in order to obtain the "difference" on 2 tables:tb1
==========
|id|name |
==========
|1 |pippo |
|2 |pluto |
|3 |xyz |
|4 |qwer |
|5 |www. |
==========
tb2
=============
|id|id_tb1|id_usr |
=============
|1 |1 |23 |
|2 |2 |23 |
|3 |3 |23 |
|4 |3 |2 |
|5 |5 |2 |
=============
with this
SELECT tb1.* FROM tb1 LEFT JOIN tb2 ON tb1.id=tb2.id_tb1 WHERE tb2.id_tb1 IS NULL
I obtain the difference in "absolute", ...
========
|id|nome |
========
|4 |qwer |
========
but I do not succeed to limit returns out to a specific "id"
(ex. SELECT tb1.* FROM tb1 LEFT JOIN tb2 ON tb1.id=tb2.id_tb1 WHERE tb2.id_tb1 IS NULL AND tb2.id_usr=23)
as to obtain the difference:
========
|id|name |
========
|1 |pippo |
|2 |pluto |
|3 |xyz |
========
can someone help me?
tnx