Ejemplos join

https://www.w3schools.com/sql/sql_join.asp

Nuestra base de datos es relacional, así que relacionamos las tablas mediante el join:


SELECT country, city, city_id
FROM country join city on country.country_id=city.country_id;

select country,city
from country join city using(country_id);

SELECT name, title FROM category join film_category
on category.category_id=film_category.category_id
join film on film_category.film_id=film.film_id;

SELECT name, title FROM category join film_category
using(category_id)
join film using(film_id);

SELECT name, title FROM category join film_category
using(category_id)
join film using(film_id)
where name in ('Family','Children') and title like '%strange%'
and rating='G'

-- ¿Qué actores han trabajado en documentales?

SELECT distinct name, first_name, last_name FROM category 
join film_category
on category.category_id=film_category.category_id
join film
on film_category.film_id=film.film_id
join film_actor
on film.film_id=film_actor.film_id
join actor
on film_actor.actor_id=actor.actor_id
where name='Documentary'
order by name, first_name, last_name

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos