Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi [SQL] Hilfe bei Abfrage (https://www.delphipraxis.net/149641-%5Bsql%5D-hilfe-bei-abfrage.html)

Grolle 25. Mär 2010 19:48

Datenbank: Firebird • Version: 2.1 • Zugriff über: Unidac

[SQL] Hilfe bei Abfrage
 
Hallo,

ich baue mit folgender Abfrage einen Baum auf:
SQL-Code:
SELECT * FROM groups ORDER BY itemlevel ASC, name ASC
jetzt möchte ich schauen, welche Kontakte welcher Gruppe zugeordnet sind. Ich brauche also alle Einträge von der Groups-Tabelle und brauche aus der contacts2groups die contact_id, wenn zugeordnet. Jetzt brauche ich nur noch einen Ansatz :roll: .

Tabellenstruktur groups: id, parent, itemlevel, name
Tabellenstruktur contacts2groups: id, contact_id, group_id

Viele Grüße ...

samso 25. Mär 2010 21:03

Re: [SQL] Hilfe bei Abfrage
 
Bringt diese Abfrage das gesuchte Ergebnis?
SQL-Code:
SELECT groups.id, groups.parent, groups.itemlevel, groups.name, contacts2groups.contact_id
FROM groups
LEFT JOIN contacts2groups ON contacts2groups.group_id=groups.id

Grolle 25. Mär 2010 21:30

Re: [SQL] Hilfe bei Abfrage
 
Hallo,

nein, ich muss ja noch einen bestimmten Kontakt haben (also ein where contacts2groups.contact_id=1 muss irgendwie noch rein). Angezeigt werden soll aber alles aus der Groups-Tabelle.

Viele Grüße ...

omata 25. Mär 2010 22:36

Re: [SQL] Hilfe bei Abfrage
 
SQL-Code:
SELECT g.id, g.parent, g.itemlevel, g.name, cg.contact_id
FROM groups g
LEFT JOIN contacts2groups cg
  ON    g.id = cg.group_id
     AND cg.group_id = 1

Grolle 26. Mär 2010 07:16

Re: [SQL] Hilfe bei Abfrage
 
Hallo,
Zitat:

Zitat von omata
SQL-Code:
SELECT g.id, g.parent, g.itemlevel, g.name, cg.contact_id
FROM groups g
LEFT JOIN contacts2groups cg
  ON    g.id = cg.group_id
     AND cg.group_id = 1

zeigt mir auch die contact_id nicht an. So geht es:
SQL-Code:
SELECT g.id, g.parent, g.itemlevel, g.name, cg.contact_id
FROM groups g
LEFT JOIN contacts2groups cg
  ON    g.id = cg.group_id
     AND cg.contact_id = 1
@omata, hattest du das wieder geändert?

Viele Grüße ...


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:11 Uhr.

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