UHU-StartseiteInformatikDatenbankenSQL: Verwendung von DBAbfragen über mehrere Tabellen
Weitere Abfrage über zwei Tabellen: Album und Interpret


Tabelle Interpret
SELECT ID, Name FROM Interpret

ID	Name
0	Cat Stevens
1	Deep Purple
2	Tokyo Hotel
3	Die Band



Tabelle Album
SELECT ID, Name, Interpret FROM Album

ID	Titel	                        Interpret
0	Smoke on the water	        1
1	Thomas und Phönix	        3
2	Kitty / Blackness of the Night	0



Abfrage über Album und Interpret
SELECT Album.ID, Titel, Album.Interpret, Name, Interpret.ID FROM Album, Interpret

Album.ID Titel	                        Interpret Name	      Interpret.ID
0	 Smoke on the water	        1  	  Cat Stevens   0
1	 Thomas und Phönix	        3	  Cat Stevens   0
2	 Kitty / Blackness of the Night	0	  Cat Stevens	0
0	 Smoke on the water	        1	  Deep Purple	1
1	 Thomas und Phönix	        3	  Deep Purple	1
2	 Kitty / Blackness of the Night	0	  Deep Purple	1
0	 Smoke on the water	        1	  Tokyo Hotel	2
1	 Thomas und Phönix	        3	  Tokyo Hotel	2
2	 Kitty / Blackness of the Night	0	  Tokyo Hotel	2
0	 Smoke on the water	        1	  Die Band	3
1	 Thomas und Phönix	        3	  Die Band	3
2	 Kitty / Blackness of the Night	0	  Die Band	3



Anfrage über Album und Interpret, mit passenden Relationen
SELECT Album.ID, Titel, Album.Interpret, Name, Interpret.ID FROM Album, Interpret WHERE Album.Interpret = Interpret.ID

Album.ID Titel	                        Album.Interpret	Name	    Interpret.ID
0	 Smoke on the water             1	        Deep Purple 1
1	 Thomas und Phönix              3	        Die Band    3
2	 Kitty / Blackness of the Night	0	        Cat Stevens 0


optimal sichtbar mit Firefox Formeln mit asciimath Druckversion