SQL 2 - Datenabfragen Flashcards

1
Q

Abfragen mit SELECT

A

SELECT < Attribut(e) > FROM < Tabelle > WHERE < Bedingung >;

WHERE ist hier Optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Alle spalten anzeigen

A

SELECT * FROM < Tabelle >;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

IN für Bedingungen

A

SELECT < Attribut(e) > FROM < Tabelle > WHERE < Attribut(e) > IN(< Aufzählung >);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

SELECT DISTINCT Abfragen

A

SELECT DISTINCT < Attribut(e) > FROM < Tabelle > WHERE
< Bedingung >
WHERE ist hier Optional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Sortierung

A

SELECT < Attribut(e) > FROM < Tabelle > ORDER BY < ASC/DESC >;

ASC - Ascending ist der Standardwert und wird eingesetzt, sollte man nicht ASC oder DESC angeben.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Aggregatfunktionen

A

AVG, COUNT, MIN, MAX, SUM jeweils nach SELECT setzen.

Beispiele: 
SELECT COUNT (*) FROM < Tabelle > gibt Anzahl der Attribute der Tabelle an 
SELECT SUM(< Attribut1 >,...) FROM  WHERE < Bedingung >; 
Summe von Attribut1 wo die Bedingung erfüllt wurde.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

GROUP BY

A

SELECT < Attribut(e) > FROM < Tabelle > GROUP BY < Attribut(e) >;

Auch nach Bedingung immer GROUP BY am ende

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Unter-Abfragen mit SELECT

A

SELECT * FROM < Tabelle1 > WHERE id =

(SELECT id FROM < Tabelle2 > WHERE < Bedingung >);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Vereinigung 2 Tabellen

A

SELECT < Attribut(e) > FROM < Tabelle1 > UNION SELECT < Attribut(e) > FROM < Tabelle2 >;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Schnitt von 2 Tabellen

A

SELECT < Attribut(e) > FROM < Tabelle1 > INTERSECT SELECT < Attribut(e) > FROM < Tabelle2 >;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Differenz 2 Tabellen

A

SELECT < Attribut(e) > FROM < Tabelle1 > EXCEPT SELECT < Attribut(e) > FROM < Tabelle2 >;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Kreuzprodukt von 2 Tabellen

A

SELECT < Attribut(e) > FROM < Tabelle1 >, < Tabelle 2 >;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

NATURAL JOIN

A

SELECT * FROM < Tabelle 1 > NATURAL JOIN < Tabelle2 >;

Nur im Fall wenn Tabelle 1 und Tabelle 2 ein gemeinsames Attribut mit demselben Namen haben

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

JOIN

A

SELECT * FROM < Tabelle1 > JOIN < Tabelle2 > ON < Bedingung >;

Jetzt können die Attribute auch unterschiedliche Namen haben.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly