@jonathan.interviews: Self-joins are one of those SQL concepts that trips people up in interviews because the syntax looks weird — you’re joining a table to itself. The classic example is an employee-manager hierarchy. One table holds both employees and their managers. The trick is referencing that same table twice using aliases: one alias represents the employee, the other represents the manager. Then you join on where the employee’s manager_id matches the manager’s employee_id. The other key decision is LEFT JOIN vs INNER JOIN. If you use INNER JOIN, you lose the CEO — she has no manager, so the join condition fails and she drops out of the result. LEFT JOIN keeps her in with a NULL for manager name. Two things interviewers look for: correct aliases so SQL knows which “copy” of the table you mean, and the right join type based on whether nulls matter for your use case. #sql #datascience #dataanalytics #codinginterview #techinterview

Data Science Interviews
Data Science Interviews
Open In TikTok:
Region: JP
Monday 30 March 2026 13:58:06 GMT
87114
3692
51
93

Music

Download

Comments

motiontt
Motion troupper :
with recursive hierarchy as ( Select from employees where idmanager is null full join select * from hierarchy inner join employees where hierarchy.idemployee = employees.idmanager) select* from hierarchy.
2026-03-31 19:10:06
1
hersh697
hersh :
imagine doin code challange when u have ai
2026-05-08 21:33:25
3
ge0metrix
geometrix :
you lost me at calling a join a “merge” … its a join … use the correct terminology so you don’t confuse new people down the road
2026-03-31 19:24:04
59
sergiomlduarte
Sérgio Duarte :
Just do it properly and create a employee_manager table. Unless this is a really small dataset (in which case you might as well just use a csv or an exel file), you're creating future scaling issues with this schema.
2026-03-31 19:46:25
7
ivngriga
Ivan :
I was waiting for some catch, quite an easy question
2026-03-30 19:57:34
28
eveykhan
evykhan :
Yeah, no catch, it might just sound unusual to do a self join. Now asking them to to show an employee's entire reporting structure all the way to the CEO would be vile in plain SQL. 😂
2026-04-02 03:29:25
1
weckdog
Weckdog :
Without seeing the data how were you supposed to know that the managers and the employees are the same set of people?
2026-03-30 14:37:14
3
charlie_bone91
charlie_bone91 :
CTE manager_id with name and then join on manager_id and select what you need
2026-04-22 14:53:26
0
yaesetti
Setti :
What is more common and efficient, an explicit JOIN like in the video or an implicit JOIN? My teacher is against explicit but Gemini says it is better
2026-04-25 16:42:23
0
mam_fajnego_kotka
Mam fajnego kotka :
Ye I got something similar at an interview, so those question happens, and after reading comments I highly recommend to start talking about how this is a bad design, and table managers should be introduced to reduce this table growing out of hand when more columns start to appear regardless of if ur applying for software engineering or data engineering position
2026-04-20 00:58:56
0
wowactivities
wowactivities :
OK but what is this Tablet structure. no First Lastname, Name Limited to 50 Ids as integer instead of sth lig bigint? salary also weird...
2026-03-31 18:06:52
2
esichmell
Evan Sich :
Which of these two minors would you recommend for a data science major? Econ or management? I feel like Econ would help with entry level roles which would then give me a better shot for higher up opportunities overtime, which is ultimately what I’d like
2026-04-03 02:10:33
0
abc050k
James :
First glance its easy, actually easy. Just left join on itself
2026-04-01 22:48:37
1
glzoler
a :
the captions could be put on top rather than blocking the words on screen. Love the vid
2026-05-23 10:25:26
1
gsutwitch
Nathan D :
I do this all the time working with HR data. Now add the second level manager from the same table.
2026-04-09 18:08:53
1
andynelson817
Andy Nelson :
I've been data engineer for 5 years, never had to do this. I assume it's because I'm in finance and not CRM/HR data
2026-03-31 20:22:50
0
jawoo2
James Wooden :
I always get hung up on self joins. just need to build up an intuition about when they're used and how they are constructed.
2026-03-30 16:44:06
4
ernestoam1244
Diego :
I am having issues landing a job interview for Data Scientist, can you help with insights?
2026-03-31 14:56:31
0
trey_way03
Trey :
Luv the content 🙏🏽💯🔥
2026-04-25 20:44:40
0
lister3000
Wallis :
I do these joins literally all day every day.
2026-04-14 11:20:51
0
pastglasgow
Past Glasgow :
An incredibly easy exercise, whatever the conditions.
2026-06-04 23:08:01
0
To see more videos from user @jonathan.interviews, please go to the Tikwm homepage.

Other Videos


About