Asocierea datelor din mai multe tabele Flashcards

1
Q

Avem doua tabele customer si address, dorim sa afisam datele clientului (first_name si last_name ) impreuna cu adresa care se afla in alt tabel..cum putem proceda ?

A

SELECT customer.first_name, customer.last_name, address.address
FROM customer JOIN address
ON address.address_id = customer.address_id;

Acesta este un exemplu de INNER JOIN iar daca clientul nu ar fi avut introdusa adresa el nici nu ar fi aparut in rezultate.

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

Cate tipuri de JOIN exista si care sunt ele ?

A

4 tipuri

Inner JOIN
LEFT JOIN
RIGHT JOIN
FULL JOIN

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

Cum functioneaza LEFT JOIN ?

A

Cand se foloseste LEFT JOIN se vor afisa toate rezultatele din tabelul din stanga si doar randurile care contin valori pentru tabelul din dreapta.

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

Cum functioneaza RIGHT JOIN ?

A

Cand se foloseste RIGHT JOIN, se vor afisa toate rezultatele tabelului din dreapta si doar randurile care contin valori pentru tabelul din stanga.

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

Cum functioneaza FULL JOIN?

A

Cand folosim FULL JOIN se vor afisa si rezultatele din tabelul din dreapta si cel din stanga chiar daca acestea nu contin valori.

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

Da-ti un exemplu de LEFT/RIGHT JOIN

A

SELECT customer.first_name, customer.last_name. address.address FROM customer
LEFT / RIGHT JOIN address ON address.address_id = customer.address_id

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

Cum se realizeaza FULL JOIN ?

A

SELECT customer.first_name, customer.last_name, address.address FROM customer
LEFT JOIN address ON address.address_id = customer.address_id
UNION
SELECT customer.first_name, customer.last_name,
address.address from customer
RIGHT JOIN address ON address.address_id = customer.address_id

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