Professional Documents
Culture Documents
SUBQUERY
1
Outline
Challenges
Subquery
Noncorrelated subquery
Correlated subquery
2
Challenges
3
Find the best match for the job with below criteria
Challenges cont.
6
Challenges cont. solved with inner join
7
Query: Query:
SELECT mc.last_name, mc.first_name, mc.phone, SELECT mc.last_name, mc.first_name,
jc.title mc.phone, jc.title
FROM my_contacts AS mc FROM my_contacts AS mc
INNER JOIN job_current AS jc NATURAL JOIN job_current AS jc
ON mc.contact_id= jc.contact_id WHERE jc.title IN (‘Cook’, ‘Hairdresser’,
WHERE jc.title IN (‘Cook’, ‘Hairdresser’, ‘Waiter’, ‘Waiter’, ‘Web Designer’, ‘Web Developer’)
‘Web Designer’, ‘Web Developer’)
Challenges
Subquery
Noncorrelated subquery
Correlated subquery
Subqueries/INNER query
10
Find last name, first name of people who live in city Memphis and state TN
Find last name, first name of people who live in city Memphis and state
TN
SUB QUERY?
Subquery – Example cont.
14
Query : Find who makes the most money out all my contacts.
Subquery – Example cont.
15
Query : Find who makes the most money out all my contacts.
Try this yourself
16
Remember : subquery may only return one single value, so each time it
runs, a row is return
RESULT
Outline 2
18
Challenges
Subquery
Noncorrelated subquery
Correlated subquery
Noncorrelated and Correlated Subquery
19
Challenges
Subquery
Noncorrelated subquery
Correlated subquery
Correlated Subquery
22