Mailinglisten-Archive |
Da ich heute ein ähnliches Problem hatte...
> ----------
> Von: Thomas Butz[SMTP:butz_(at)_gum.de]
>
> ich habe zwei tabellen
>
> table A
>
> A.field1 A.field2
> 1 wert
> 2 wert
> 4 wert
> 5 wert
> 7 wert
> 9 wert
>
> table B
>
> B.field1 B.field2
> 1 wert
> 2 wert
> 3 wert
> 6 wert
> 7 wert
> 9 wert
> 10 wert
>
> Ich möchte alle Treffer von B haben die in A nicht vorkommen ( also 3,7,
> 10)
> Wie muss ich das angehen?
> SELECT * FROM A, B where A.field1 != B.field1
> bringt ja keine sinnvolle Treffermenge :(
>
select B.field1 from A left join B on A.field1 = B.field1
where B.field1 IS Null
Aus dem Manual:
JOIN SYNTAX
If there is no matching record for the right table in the ON or USING part
in a LEFT JOIN, a row with all columns set to NULL is used for the right
table. You can use this fact to find records in a table that have no
counterpart in another table:
mysql> select table1.* from table1
LEFT JOIN table2 ON table1.id=table2.id
where table2.id is NULL;
Grüße, Mathias
---
*** Weitere Infos zur Mailingliste und MySQL unter http://www.4t2.com/mysql
php::bar PHP Wiki - Listenarchive