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.
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.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnSQL/co...