Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi [SQL] Finden von nicht existierenden Relationen? (https://www.delphipraxis.net/62610-%5Bsql%5D-finden-von-nicht-existierenden-relationen.html)

Igotcha 7. Feb 2006 11:16

Datenbank: mySQL • Version: 5.x • Zugriff über: ZEOS

[SQL] Finden von nicht existierenden Relationen?
 
Hallo zusammen,

ich stehe etwas auf dem Schlauch, da ich eine Abfrage erstellen möchte, die auswirft, wo eine Relation nicht existiert.

2 Tabellen sind gegeben:
Delphi-Quellcode:
TABELLE1
========

PID     Bezeichnung Status
12345678 Test1         -1
23456789 Test2          0
...

TABELLE2
========

ID PID     MONAT JAHR
0  12345678 1    2006
1  12345678 3    2006
...
Parameter sind MONAT=2 und JAHR=2006.

Ich möchte jetzt als Ergebnis haben:

- alle Datensätze aus Tabelle1 (PID ist eindeutig)
- die den Status "-1" besitzen und
- für die kein Eintrag in Tabelle2 für MONAT=2 und JAHR=2006 existiert

Danke und Grüße
Igotcha

mkinzler 7. Feb 2006 11:20

Re: [SQL] Finden von nicht existierenden Relationen?
 
select * from tabelle1 t1 where status = -1 and not exists( select * from tabelle2 where PID = t1.PID and MONAT=2 and JAHR=2006)

Igotcha 7. Feb 2006 11:26

Re: [SQL] Finden von nicht existierenden Relationen?
 
Zitat:

Zitat von mkinzler
select * from tabelle1 t1 where status = -1 and not exists( select * from tabelle2 where PID = t1.PID and MONAT=2 and JAHR=2006)

Ja super, vielen Dank!


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:15 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz