aktuelle.kurse/m151/docs/uebungsunterlagen/03 SQL_JOIN_Übung/SQL_JOINS.txt
harald.mueller@tbz.ch 441c8b4af4 muh
2021-08-09 14:54:10 +02:00

54 lines
1.8 KiB
Plaintext

SELECT COUNT(FS_Rechnung) FROM tbl_trans
SELECT name, COUNT(vorname) FROM tbl_personen group by name
SELECT FS_Rechnung, COUNT(FS_Artikel) FROM tbl_trans GROUP BY FS_Rechnung
SELECT * FROM tbl_personen, tbl_rechnungen
Beispiel für einen Full-Join (kartesisches Produkt
SELECT * FROM tbl_personen, tbl_rechnungen
WHERE tbl_personen.Person_ID = tbl_rechnungen.Person_FS
SELECT * FROM tbl_personen INNER JOIN tbl_rechnungen
ON tbl_personen.Person_ID = tbl_rechnungen.Person_FS
SELECT * FROM tbl_personen LEFT JOIN tbl_rechnungen
ON tbl_personen.Person_ID = tbl_rechnungen.Person_FS
SELECT * FROM tbl_personen RIGHT JOIN tbl_rechnungen
ON tbl_personen.Person_ID = tbl_rechnungen.Person_FS
SELECT * FROM tbl_personen AS p INNER JOIN tbl_rechnungen AS r
ON p.Person_ID = r.Person_FS
INNER JOIN tbl_trans AS t ON r.Rechnungs_ID = t.FS_Rechnung
ORDER BY Person_ID
SELECT * FROM tbl_personen AS p INNER JOIN tbl_rechnungen AS r
ON p.Person_ID = r.Person_FS
INNER JOIN tbl_trans AS t ON r.Rechnungs_ID = t.FS_Rechnung
INNER JOIN tbl_artikel AS a ON t.FS_Artikel = a.Artikel_ID
ORDER BY Person_ID
SELECT * FROM tbl_personen AS p INNER JOIN tbl_rechnungen AS r
ON p.Person_ID = r.Person_FS
INNER JOIN tbl_trans AS t ON r.Rechnungs_ID = t.FS_Rechnung
LEFT OUTER JOIN tbl_artikel AS a ON t.FS_Artikel = a.Artikel_ID
ORDER BY Person_ID
SELECT * FROM tbl_personen AS p INNER JOIN tbl_rechnungen AS r
ON p.Person_ID = r.Person_FS
LEFT OUTER JOIN tbl_trans AS t ON r.Rechnungs_ID = t.FS_Rechnung
LEFT OUTER JOIN tbl_artikel AS a ON t.FS_Artikel = a.Artikel_ID
ORDER BY Person_ID
SELECT * FROM tbl_personen AS p LEFT OUTER JOIN tbl_rechnungen AS r
ON p.Person_ID = r.Person_FS
LEFT OUTER JOIN tbl_trans AS t ON r.Rechnungs_ID = t.FS_Rechnung
LEFT OUTER JOIN tbl_artikel AS a ON t.FS_Artikel = a.Artikel_ID
ORDER BY Person_ID