...

/

Nested Column Queries

Nested Column Queries

This lesson discusses nested queries that return a column of values.

We'll cover the following...

Nested Column Queries

In the previous lesson we examined nested queries that returned a single value. In this lesson we’ll see nested queries that return values belonging to the same column.

Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/31lesson.sh and wait for the MySQL prompt to start-up.

Press + to interact
-- The lesson queries are reproduced below for convenient copy/paste into the terminal.
-- Query 1
SELECT * FROM Actors
INNER JOIN DigitalAssets ON ActorId=Id
WHERE AssetType = ANY (SELECT DISTINCT AssetType
FROM DigitalAssets
WHERE AssetType != 'Website');
-- Query 2
SELECT * FROM Actors
INNER JOIN DigitalAssets ON ActorId=Id
WHERE AssetType != 'Website';
-- Query 3
SELECT FirstName, SecondName
FROM Actors
WHERE Id = ANY (SELECT ActorId
FROM DigitalAssets
WHERE AssetType = 'Facebook');
-- Query 4
SELECT FirstName, SecondName
FROM Actors
WHERE Id IN (SELECT ActorId
FROM DigitalAssets
WHERE AssetType = 'Facebook');
-- Query 5
SELECT FirstName, SecondName
FROM Actors
WHERE NetworthInMillions > ALL (SELECT NetworthInMillions
FROM Actors
WHERE FirstName LIKE "j%");
Terminal 1
Terminal
Loading...
  1. We’ll use a slightly contrived example this time. Imagine we want to list all the social media accounts for all the actors, except for their personal websites. From our database schema ...

Access this course and 1400+ top-rated courses and projects.