![]() |
Datenbank: Firebird • Version: 2.1 • Zugriff über: IBDAC
SQL-Problem mal wieder
Hallo,
ich habe mal wieder ein kleines Problem mit einer Abfrage:
SQL-Code:
Die Tabellen sehen so aus:
SELECT tree.id, tree.name, tree2contact.contact_id FROM tree left join
tree2contact on tree.id = tree2contact.tree_id where tree2contact.contact_id=22
SQL-Code:
Ich will jetzt alle tree.name die tree.parent=0 ohne Dubletten(tree.name) und tree2contact.contact_id=22 (oder 0 wenn nicht zugeordnet).
Tree
--------- id name parent tree2contact --------- id tree_id contact_id Viele Grüße ... |
Re: SQL-Problem mal wieder
Hallo,
jaaaaa, wo ist denn das Problem ? Zitat:
SQL-Code:
Select Distinct(Tree.Name), Tree.Id ...
Zitat:
SQL-Code:
oder
Where ((tree2contact.contact_id=22) or (tree2contact.contact_id=0))
SQL-Code:
Where ((tree2contact.contact_id=22) or (tree2contact.contact_id is Null))
Heiko |
Re: SQL-Problem mal wieder
Zitat:
|
Re: SQL-Problem mal wieder
Hallo,
tree.parent=0 hatte ich noch vergessen. Heiko |
Re: SQL-Problem mal wieder
Hi,
so ganz klappt das immer noch nicht. Die Anfrage sieht jetzt so aus:
SQL-Code:
Bei Abfragen mit unterschiedlicher (tree2contact.contact_id=25) bekomme tree.name verschiedener Anzahl? Eigentlich müsste er mir doch alle rausschmeißen, oder überseh ich da was?
SELECT distinct(tree.name) as name, tree.id as id, tree2contact.contact_id as contact_id from tree left join tree2contact on tree.id=tree2contact.tree_id
Where ((tree2contact.contact_id=25) or (tree2contact.contact_id is Null)) and tree.parent=0 order by tree.name Viele Grüße ... |
Re: SQL-Problem mal wieder
Hallo,
du willst also nur einen Datensatz haben, oder was ist mit Zitat:
Mal bitte Bsp.-Daten und was rauskommen soll. Heiko |
Re: SQL-Problem mal wieder
SQL-Code:
Tree
(ID, NAME, PARENT) (6, 'Kunden', 0); (8, 'Behörden', 0); (9, 'Banken', 0); (10, 'Intern', 6); Tree2Contact (ID, TREE_ID, CONTACT_ID) (1, 8, 22); (2, 6, 25); (3, 6, 22);
SQL-Code:
soll:
SELECT distinct(tree.name) as name, tree.id as id, tree2contact.contact_id as contact_id from tree left join tree2contact on tree.id=tree2contact.tree_id
Where ((tree2contact.contact_id=25) or (tree2contact.contact_id is Null)) and tree.parent=0 order by tree.name ('Banken', 9, NULL); ('Behörden', 8, NULL); ('Kunden', 6, 25); ist: ('Banken', 9, NULL); ('Kunden', 6, 25); bei:
SQL-Code:
soll:
SELECT distinct(tree.name) as name, tree.id as id, tree2contact.contact_id as contact_id from tree left join tree2contact on tree.id=tree2contact.tree_id
Where ((tree2contact.contact_id=22) or (tree2contact.contact_id is Null)) and tree.parent=0 order by tree.name ('Banken', 9, NULL); ('Behörden', 8, 22); ('Kunden', 6, 22); und ist auch so. (Teste mit IBExpert) viele Grüße ... |
Re: SQL-Problem mal wieder
Hallo,
melkwüldig ;) Hänge mal die FDB an den 1. Thread an, oder poste sie mal mit Hinweis auf den vorigen. Heiko |
Re: SQL-Problem mal wieder
SQL-Code:
alex
SELECT
distinct(tree.name) as name, tree.id as id, tree2contact.contact_id as contact_id from tree left join tree2contact on tree.id=tree2contact.tree_id and ((tree2contact.contact_id=25) or (tree2contact.contact_id is Null)) Where tree.parent=0 order by tree.name |
Re: SQL-Problem mal wieder
Hallo alex517,
wo ist da der Unterschied ? (interessiert mich wirklich) der Left Join bezieht sich ja nur auf das Tree(Id) Heiko |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:23 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