Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

9
Nested Select Statement Has Me a Bit Confused
Post Body

howdy ya'll, I'm relatively new to SQL and taking a course that uses NASA data from the cassini space mission.

There's a query I'm seeing that kiiiind of makes sense, but I want to make sure I'm understanding what it's doing under the hood.

For reference, there's a table called teams, that has 14 distinct team names and a team id as a primary key. There is also a table called master_plan that has a team column with the same names but repeated a bunch because there's ~64k entries.

The nested select in the following code is what's got me scratching my head:

insert into plans(start, title, team_id, description)
select
    start_time_utc::timestamp,
    title,
    (select id from teams where name = csvs.master_plan.team),
    description
    from csvs.master_plan
    where target = 'Enceladus' and title is not null;

is the nested select basically iterating through each row in the master_plan and then using the smaller table called teams as a lookup table like in excel to pull the id? like literally going row by row by row by row etc etc. I get that its creating a column of the id, but I guess the logic has me somewhat confused.

If I switched it to:

(select id from teams where csvs.master_plan.team = name)

would that work? to me that makes sense as in each row of master plan's team column uses the teams table to look up the corresponding id.

Author
Account Strength
90%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,745
Link Karma
940
Comment Karma
805
Profile updated: 5 days ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago