SQL Subselect
SQL Subselect Example One
Select Film_Title
From Thespian_Film_Table
Where Thespian_Last_Name = "Ford"
and Thespian_First_Name = "Harrison"
and Film_Title in
(Select Film_Title
From Film_Table
Where Film_Year equals "1984");
Indiana Jones and the Temple of Doom
SQL Subselect Example Two - Not In
Select Film_Title
From Thespian_Film_Table
Where Thespian_Last_Name = "Ford"
and Thespian_First_Name = "Harrison"
and Film_Title not in
(Select Film_Title
From Film_Table
Where Film_Year equals "1984");
Air Force One American Graffiti Apocalypse Now Blade Runner Clear and Present Danger Frantic Hanover Street Heroes Indiana Jones and the Last Crusade Patriot Games Presumed Innocent Raiders of the Lost Ark Regarding Henry Return of the Jedi Six Days Seven Nights Star Wars The Empire Strikes Back The Frisco Kid The Fugitive The Mosquito Coast Working Girl
SQL Subselect Example Three - A Correlated Subquery
Select Thespian_Film_Table.Film_Title
From Thespian_Film_Table
Where Thespian_Last_Name = "Ford"
and Thespian_First_Name = "Harrison"
and exists
(Select *
From Director_Film_Table
Where Director_Last_Name = "Lucas"
and Director_First_Name = "George"
and Director_Film_Table.Film_Title
= Thespian_Film_Table.Film_Title);
American Graffiti Star Wars
The first select gets all Harrison Ford movies. The second select gets all Harrison Ford movies Directed by George Lucas. The statement "and Director_Film_Table.Film_Title = Thespian_Film_Table.Film_Title" in the subselect is where both tables are "tied together" or correlated.
| Comments Comments are left by visitors to FluffyCat.com and may or may not be accurate. |
| Comment by TheMadProfessor on 2013-05-22 Rate this Comment |
A couple of comments regarding IN/EXISTS:
|
| Sign in to comment on SQL Subselect. |