Autor Beitrag
coder24h
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48



BeitragVerfasst: Di 29.11.05 22:02 
Hallo zusammen, ich melde mich noch mal da ich nicht verstehe was Sache ist. Mit Hilfe von MySQL versuche ich an das Inhalt einer Tabelle zu gelangen, wenn dieses nicht in einer anderen Tabelle vorkommt:
ausblenden SQL-Anweisung
1:
2:
3:
SELECT tp.id_position
FROM t_position tp, rel_article_position_worker rapw 
WHERE  (tp.id_position <> rapw.id_position)

Leider bekomme nicht das erwünschte Ergebnis.Also nur die Datensätze anzeigen lassen, wenn der Schlüssel id_position nicht in zweiter Tabelle vorkommt. Kann jemand mir sagen was ich hier falsch mache?

Moderiert von user profile iconraziel: Code- durch SQL-Tags ersetzt
espen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90
Erhaltene Danke: 1


D6 Prof./D7 Prof. MSSQL, MySQL
BeitragVerfasst: Mi 30.11.05 14:52 
Hi,

probiere es mal so:

ausblenden SQL-Anweisung
1:
2:
3:
SELECT tp.id_position
FROM t_position tp
WHERE tp.id_position NOT IN (SELECT rapw.id_position FROM rel_article_position_worker rapw)
coder24h Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48



BeitragVerfasst: Mi 30.11.05 19:26 
Hei espen, ich bin froh über deine Antwort! Leider macht mein MySQL mit dieser Anweisung nicht mit. SQL Anführungsfehler 1064! Mit etwas modifizierter Anweisung

ausblenden SQL-Anweisung
1:
2:
3:
SELECT tp.id_position
FROM t_position tp
WHERE tp.id_position NOT IN ('SELECT rapw.id_position FROM rel_article_position_worker rapw')


wird kein Fehler produziert, nur die Datenmenge die ich bekomme ist immer noch die Falsche. In der Tabelle rel_article_position_worker sind 31 Datensätze (1-31) und in der t_position 42 (1-42)! Bei der oben genannten Anweisung werden alle 42 Datensätze 1-42 angezeigt und ich bin genauso ratlos wie vorher ;(
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 30.11.05 20:35 
Das Problem ist, dass Du von einer Tabelle die Datensätze haben willst, die nicht in einer anderen Menge (Tabelle) vorhanden sind. Mir fällt da nichts anderes ein als ein Subselect. Aber eben dieser wird nicht von mySQL bis Version 4.0 (glaube ich) unterstützt. Somit wird das nicht in SQL direkt gehen. Du musst das also im Programm machen ... außer jemand andere fällt eine Möglichkeit ein.
Lake
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78


D6 prof., Delphi 10.2 Tokyo
BeitragVerfasst: Mi 30.11.05 21:02 
Wenn Du wissen willst welche Datensätze in Worker nicht vorhanden sind, dann nimm folgendes Statement:

ausblenden SQL-Anweisung
1:
2:
3:
Select po.pos 
from pos.db po left join worker.db wo on po.pos=wo.pos 
where wo.pos is null
coder24h Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48



BeitragVerfasst: Mi 30.11.05 21:18 
Danke UGrohne, das hilft mir zu verstehen warum das so nicht funktioniert hat.

Deine Variante Lake habe ich selber schon vorher ausprobiert, jedoch ohne IS NULL .., was natürlich nicht das hergegeben hat was ich brauchte. Deine komplette Anweisung ist meine Rettung und bringt mich endlich weiter!

Einfach nur DANKE an ALLE!
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 30.11.05 21:22 
user profile iconLake hat folgendes geschrieben:
Wenn Du wissen willst welche Datensätze in Worker nicht vorhanden sind, dann nimm folgendes Statement:

ausblenden SQL-Anweisung
1:
2:
3:
Select po.pos 
from pos.db po left join worker.db wo on po.pos=wo.pos 
where wo.pos is null

Gute Idee, daran hatte ich jetzt nicht gedacht, muss ich mir gleich mal notieren ;-)