JOINS Flashcards

1
Q

SELECT customer_id, SUM(amount) AS total_spent_by_customer
FROM payment
GROUP BY customer_id
HAVING SUM(amount) > 100;

A

creating alias of total_spent_by_customer, cannot use alias name in query-will throw an error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
SELECT * FROM payment
FULL OUTER JOIN customer
ON customer.customer_id = payment.customer_id
WHERE payment.payment_id IS NULL 
OR customer.customer_id IS NULL
A

produces opposite of an inner join

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

SELECT COUNT(inventory.film_id) AS number_of_copies, store_id, title FROM inventory
FULL JOIN film
ON film.film_id = inventory.film_id
GROUP BY inventory.film_id, store_id, title
ORDER BY title

A

provides a list of number of copies of movies by store

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

SELECT COUNT(inventory.film_id) AS number_of_copies, store_id, title FROM inventory
FULL JOIN film
ON film.film_id = inventory.film_id
WHERE inventory_id IS null
GROUP BY inventory.film_id, store_id, title
ORDER BY title

A

provides list of movies that no stores have in possession

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
SELECT film.film_id, title, inventory_id
FROM film
LEFT JOIN inventory 
ON inventory.film_id = film.film_id
WHERE inventory.film_id IS null
A

left outer join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
SELECT COUNT(amount) AS num_transactions
FROM payment;
A

provides alias for COUNT(amount) value

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

SELECT title, first_name, last_name FROM film
INNER JOIN film_actor
ON film_actor.film_id = film.film_id
INNER JOIN actor
ON film_actor.actor_id = actor.actor_id
WHERE first_name = ‘Nick’ AND last_name = ‘Wahlberg’;

A

used to connect three tables together , you can do multiple inner joins.

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