SQL Foundations I Module 3

Write 4 queries with different subqueries

Only editable by group admins

  • Last updated November 13, 2017 at 4:52 PM
  • Evidence visible to public
Four queries will use subqueries for different reasons (ie, one query might be a correlated subquery to find duplicate values while another query might find a local maximum value). Submit a link to show your work.

All posted evidence

Query 4

SELECT first_name 'First Name, surname 'Last Name', m.title 'Movie', m.year_released-born 'Age at release' FROM people p
LEFT JOIN
(SELECT * FROM movies m
INNER JOIN credits
ON m.movieid = c.movieid
WHERE p.born < m.year_released) c
ON c.peopleid = p.peopleid
WHERE c.credited_as = 'A'
ORDER BY m.year_released-born asc;
mpurnell1 About 7 years ago

Query 3

SELECT title 'Movie', first_name 'First Name', surname 'Last Name' FROM people
LEFT JOIN
(SELECT * FROM credits
INNER JOIN movies USING(movieid)
WHERE credited_as = 'A')
USING(peopleid)
WHERE country = 'fr'
ORDER BY surname desc;
mpurnell1 About 7 years ago

Query 2

SELECT m.title 'Main Title', a.title 'Alt Title', year_released 'Released in' FROM movies m
LEFT JOIN
(SELECT * FROM alt_titles
WHERE LENGTH(title) > 2) a
ON m.title = a.title
WHERE country = 'gb'
ORDER BY m.title;
mpurnell1 About 7 years ago

Query 1

SELECT title FROM movies
WHERE movieid IN
(SELECT movieid FROM credits
INNER JOIN people USING(peopleid)
WHERE died - born < 30)
ORDER BY title;
mpurnell1 About 7 years ago

Results for Query 11

jmfisher About 7 years ago

Additional Query for Task 6

/*Query 11 -Actors with more than 20 credits to their name*/
SELECT COUNT(*) as 'Number of Actors with More than 20 Credits' FROM(SELECT peopleid FROM CREDITS WHERE credits.credited_as="A" GROUP BY credits.peopleid HAVING COUNT(*)>20);
jmfisher About 7 years ago

All Queries from Task 3 use Subqueries

Query 5 contains a subquery to list movies that have come out since 2012 and their credits
Query 6 contains a subquery to list all alternate titles that are less than 20 characters long
Query 7 contains a subquery to list movies made in the US and their credited director
jmfisher About 7 years ago

Find only directories with more than 15 files using a SUBQUERY.

jaco About 8 years ago

Gets name and age from a SUBQUERY.

jaco About 8 years ago

Uses a SUBQUERY to filter information from multiple tables combined.

jaco About 8 years ago

SUBQUERY to filter out unnecessary info in a query to find actors in movies with long names.

jaco About 8 years ago

Kept it simple and used the Konagora DB http://edu.konagora.com/SQLsandbox.php

Pastebin

SELECT * FROM credits NATURAL JOIN movie_title_ft_index2 WHERE title_wor - Pastebin.com

Pastebin PRO Accounts CHRISTMAS SPECIAL! For a limited time only get 50% discount on a LIFETIME PRO account! Offer Ends Soon!
randyiv About 8 years ago