Union oder nicht?

06/05/2008 - 15:13 von Volker Strähle | Report spam
Guten Tag,

ich habe 2 Tabellen pd und pdv.

Tabelle pd:
product_details_id product_details_name languages_id
1 nme1deu 1
1 nme1engl 2
2 nme2deu 1
2 nme2engl 2

Tabelle pdv:
product_details_id product_id languages_id product_details_value
1 101 1 rot
1 101 2 red
2 101 1
fluessig

Meine Abfrage soll liefern:
product_details_id product_details_name languages_id product_id
product_details_value
1 nme1deu 1
101 rot
1 nme1engl 2
101 red
2 nme2deu 1
101 fluessig
2 nme2engl 2

Meine Lösung:
SELECT pd.products_details_id, pd.products_details_name, pdv.products_id,
pdv.languages_id, pdv.products_details_value

FROM pd LEFT JOIN pdv ON pd.languages_id = pdv.languages_id and
pd.products_details_id = pdv.products_details_id

where pd.languages_id = 1' and pdv.products_id = 2'

Union

SELECT pd.products_details_id, pd.products_details_name, '' AS products_id,
pd.languages_id, '' AS products_details_value

FROM pd

WHERE pd.products_details_id Not In (SELECT pd.products_details_id

FROM pd LEFT JOIN pdv ON pd.languages_id = pdv.languages_id and
pd.products_details_id = pdv.products_details_id

where pd.languages_id = 1' and pdv.products_id = 2' ) AND pd.languages_id= 1



Meine Frage:

Geht das auch ohne Union?



Danke



Volker
 

Lesen sie die antworten

#1 Stefan Hoffmann
06/05/2008 - 15:38 | Warnen spam
hallo Volker,

Volker Stràhle schrieb:
Meine Frage:
Geht das auch ohne Union?


Wenn ich richtig gelesen habe, ja:

SELECT pd.*, pdv.*
FROM pd
INNER JOIN pdv
ON pd.product_details_id = pdv.product_details_id
AND pd.languages_id = pdv.languages_id


mfG

Ähnliche fragen