Solving an SQL Interview Problem | Find Child - Parent - Grandparent Hierarchy using SQL

  Рет қаралды 30,415

techTFQ

techTFQ

Күн бұрын

Пікірлер: 70
@techTFQ
@techTFQ 10 ай бұрын
OdinSchool Bootcamp link: hubs.la/Q024h4NC0 Success stories page link: hubs.la/Q024h4Xz0
@naveenkumar-pm2si
@naveenkumar-pm2si 10 ай бұрын
Hi, Thought of registering for your sql course but couldnt find a link Could you please help me on this
@parvchopra1456
@parvchopra1456 10 ай бұрын
hii sir hope you are doing well sir could you please make a video or could you please tell ,how to master SQL ?
@sujaa1000
@sujaa1000 6 ай бұрын
One of the best KZfaq channel for SQL! Thanks TFQ!
@zewduwereta302
@zewduwereta302 10 ай бұрын
Very interesting problem! I like the way you dissect the problem into different parts, it makes easier to approach it! Thanks!👍👍
@Madhusudan_Sarkate
@Madhusudan_Sarkate 10 ай бұрын
Best explanation ever hard problems look like simple
@attilapekkaszabo-iv6tl
@attilapekkaszabo-iv6tl 10 ай бұрын
Best tutor for SQL, easy to follow and very detailed explanation. Must follow and subscribe if you want to solve interesting SQL problems.
@user-xn4tu7qn3r
@user-xn4tu7qn3r 10 ай бұрын
JazakAllah. Very convenient solution to a complex problem. May Allah bless you.
@techTFQ
@techTFQ 8 ай бұрын
Thank you very much 😊
@Samcrazy4u
@Samcrazy4u 10 ай бұрын
Thanks toufiq Bhai, for helping Data community and and sharing knowledge & experience 😊, it helps a lot to understand self join
@SrikanthSSSSSS
@SrikanthSSSSSS 10 ай бұрын
Thank you sir, I developed my SQL with your videos only
@reachbharathan
@reachbharathan 10 ай бұрын
I think this problem should be the best example for demoing the usecase for self join
@avi8016
@avi8016 10 ай бұрын
Great explanation of self join Thankyou sir for this video!
@krantikumar894
@krantikumar894 10 ай бұрын
Self join is the best way to answer this question
@ashu7863
@ashu7863 10 ай бұрын
Please share this session also
@user-hv3iq8ur3l
@user-hv3iq8ur3l 10 ай бұрын
great video as always, it was well explained.
@soundarsswag7386
@soundarsswag7386 10 ай бұрын
Select count(1) from person a Where status =Alive And exists ( select 1 from persons Where a.parent = b. Person)
@Manzur.A
@Manzur.A 10 ай бұрын
You are the BEST!
@AviralOjha
@AviralOjha 10 ай бұрын
May Allah always be by your side my brother. You are like one of his greatest blessings on 🌎❤ The way you have explained and brought the best solution out is commendable! Ankit Bansal makes things over complicated, neither do I enjoy his style of teaching. We are meant to learn from you!
@techTFQ
@techTFQ 8 ай бұрын
Thank you very much brother 😊 All the best
@venkeenkokku
@venkeenkokku 10 ай бұрын
This correlated sub-query will yield the result as required --- select c.person from persons c where exists ( select null from persons p where c.parent = p.person and exists ( select null from persons g where g.person= p.parent and g.status = 'Alive'))
@gontlakowshik2345
@gontlakowshik2345 10 ай бұрын
We can use self join
@Krishna48784
@Krishna48784 10 ай бұрын
Thank you for sharing, nice explanation. When will you start postgresql Boot camp
@reachbharathan
@reachbharathan 10 ай бұрын
Thanks a lot , I understood everything, great explanation, i question what the last part select count( 1) , are we doing a grouping?
@fathimafarahna2633
@fathimafarahna2633 10 ай бұрын
Great video again 👍👍
@vinodlondhe-cm8lz
@vinodlondhe-cm8lz 8 ай бұрын
Your great sir
@HARSHRAJ-wz2rp
@HARSHRAJ-wz2rp Ай бұрын
select * from persons; with cte as( select P2.person,P1.parent as "Grandfather" FROM persons P1 JOIN persons P2 ON P1.person=p2.parent ) select COUNT(*) FROM cte JOIN persons ON cte.Grandfather=persons.person where person_status="Alive"; hoto gaya per kaise gaya woh nahi pata
@santhoshkumar6760
@santhoshkumar6760 10 ай бұрын
Solved the same kind of problem with scenario employee, manager, managers_ manager using self join
@santhoshkumar6760
@santhoshkumar6760 10 ай бұрын
N i loved the way of explanation, it's giving interest more n more Thanks
@aimanansarmomin4542
@aimanansarmomin4542 8 ай бұрын
I am not from technical background but learning sql. When we open list of the tables ,I am not able to find the parent table among all tables please guide me on this..
@aravindt1596
@aravindt1596 10 ай бұрын
Hi I want to triggers in postgresql
@swethaveluguri9115
@swethaveluguri9115 10 ай бұрын
I'm facing a SQL interview question repeateadly. "Why a stored preocedure is executing fine till yesterday and today it is taking long time to execute" [indexes are not dropped/no changes to this query]. Can you please explain this question ?
@venkeenkokku
@venkeenkokku 10 ай бұрын
Either data in the table got added over period of time, which caused underlying data distribution change OR Failure to refresh to stats on regular basis OR both
@azejlee
@azejlee 7 ай бұрын
thanks a lot!!!!!!!
@ChinweOge1
@ChinweOge1 10 ай бұрын
Tfq makes sql look so simple
@sachingunjal7347
@sachingunjal7347 10 ай бұрын
hope this solution is acceptable -- select P1.person as self, P2.person as Parent, P3.Person as GP, P1.person_status as GP_Status from Persons as P1 Right join Persons as P2 on P1.parent = P2.Person right join Persons as P3 on P2.parent = P3.Person where P1.person_status = 'Alive'
@user-jg8mo8vu5g
@user-jg8mo8vu5g 3 ай бұрын
Thank you, very useful video. I have a similar task but with more than 10 levels of hiereachy. Not sure if this is a good idea to use self join more than 10 times. Any suggestions?
@matthias7534
@matthias7534 Ай бұрын
Cde with recursive select query
@matthias7534
@matthias7534 Ай бұрын
He made a video on it as well kzfaq.info/get/bejne/gsB3lLWUqd7OaH0.html
@throughmyglasses9241
@throughmyglasses9241 10 ай бұрын
with recursive parents as ( select person,parent,CAST(NULL as varchar(10)) as son, 1 as level from people where person not in (select parent from people) union all select p2.person,p2.parent,p1.person,level+1 from parents as p1 inner join people as p2 on p1.parent=p2.person where p2.status='Alive') select count(*) from parents where level>=3;
@user-mm6sp1tc4p
@user-mm6sp1tc4p 10 ай бұрын
Hello, Would you please solve quastion like this for python(panda)?
@Rajendra-b6t
@Rajendra-b6t Ай бұрын
SELECT count(1) FROM persons c JOIN persons P ON p.PERSON = c.parent join persons GP on GP.PERSON = p.parent where GP.person_status = 'Alive'
@krishnakumarkumar5710
@krishnakumarkumar5710 10 ай бұрын
Query solving with Odni school ad
@rishabhgupta1029
@rishabhgupta1029 10 ай бұрын
with table_A as ( select t1.*, t2.parent as grand_parents from persons as t1 left join persons as t2 on t1.parent = t2.person ) select count(*) from table_A as t1 left join persons as t2 on t1.grand_parents = t2.person where t2.person_status ='Alive' ;
@sameerambre2696
@sameerambre2696 10 ай бұрын
I am not sure whether I am right here but, this is what I understand. Parent of B is Y and Y's grandparent is Y1 and the status of Y1 is Alive. Can you please help me understand why that record is not coming in your result set?
@PriyankaVijay-pm1wc
@PriyankaVijay-pm1wc 3 ай бұрын
I hope you are checking the status of y1 in parent table. You should see y1 status from name of person then check the status of the person . X1 is alive and y1 is dead
@satyamace
@satyamace 8 ай бұрын
I don't know why my one line code is working perfectly: select person from persons where parent in (select person from persons where parent in (select person from persons where person_status='Alive'));
@varuntirupati2566
@varuntirupati2566 10 ай бұрын
select count(p.person) as persons from persons p inner join persons gp on p.parent = gp.person inner join persons gp2 on gp.parent = gp2.person where gp2.person_status = 'Alive';
@vishalsonawane.8905
@vishalsonawane.8905 7 ай бұрын
Done
@sreejeshjnair6755
@sreejeshjnair6755 10 ай бұрын
Self join is a solution
@nivisworld1513
@nivisworld1513 10 ай бұрын
sir.....please post sql classes from scratch......you said will post 1st week of September but not posted......please sir post those classes.......
@swapnilsolanki8595
@swapnilsolanki8595 10 ай бұрын
Another way of writing query for same problem with recursive cte1 as ( select * from test where par_name in (select p_name from test) ), cte2 as ( select *, 1 as level from cte1 union select c1.*, level + 1 as level from cte1 c1 join cte2 c2 on c2.par_name = c1.p_name ) select count(1) from ( select cte2.p_name, cte2.par_name, t.status from cte2 join test t on cte2.par_name = t.p_name where level = 2 and t.status = 'Alive' ) subquery
@anudeepreddy5559
@anudeepreddy5559 9 ай бұрын
Plsql bootcamp please
@palbabu33
@palbabu33 10 ай бұрын
posting before watching your solution: SELECT C.PERSON AS CHILD, C.PARENT AS PARENT, P.PARENT AS GPARENT, GP.PERSON_STATUS FROM STATUS C JOIN STATUS P ON C.PARENT = P.PERSON JOIN STATUS GP ON P.PARENT = GP.PERSON WHERE GP.PERSON_STATUS = 'ALIVE';
@vrajsomeshvari3825
@vrajsomeshvari3825 10 ай бұрын
great
@techTFQ
@techTFQ 8 ай бұрын
SQL Server problem solving
@shitalredij
@shitalredij 15 күн бұрын
self join
@user-vb1fu8qy4d
@user-vb1fu8qy4d 10 ай бұрын
Self join
@KoushikT
@KoushikT 10 ай бұрын
################ My Solution using CTE ################ with A as ( select p1.person as person, p2.parent as grandparent from persons p1 join persons p2 on p1.parent=p2.person) select count(A.person) as alive_count from A join persons p on A.grandparent = p.person where p.person_status='Alive'
@TheAbhisai
@TheAbhisai 10 ай бұрын
Natural joins
@viswaskumarsurapaneni72
@viswaskumarsurapaneni72 10 ай бұрын
Slefjoin a 1 with a2 on a1.person =a2.parent
@abir95571
@abir95571 10 ай бұрын
You’ll have to do 3 self joins as the live status is on person not parent.
@ChanduMuddasani
@ChanduMuddasani 10 ай бұрын
Please explain slow and clear I didn't understand this vedio
@DeanMarko-ex3rd
@DeanMarko-ex3rd 10 ай бұрын
Not be annoying but this is a dumb question. But I love your videos
@cartercordingley6062
@cartercordingley6062 10 ай бұрын
I use a question like this but with an org chart. And I throw in n levels. Of find all employees under the CSO This question let me know if they can understand how to loop through an unknown amount of data. A lot of people will not use loops and just use joins, which is incorrect. But if they use recursive cte, cursor, or even pass it to a CLR or other program like Python or a C# to do a loop, they pass.
@sss-hk9tt
@sss-hk9tt 10 ай бұрын
Pks explain snowflakes in sql
@Oracle_developer
@Oracle_developer 10 ай бұрын
Self join
@shashigowdar7359
@shashigowdar7359 10 ай бұрын
self join
REAL SQL Interview Problem | Hierarchical data in SQL
22:09
Happy birthday to you by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 12 МЛН
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 3,6 МЛН
Little brothers couldn't stay calm when they noticed a bin lorry #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 20 МЛН
Google SQL Interview Problem | Solving SQL Interview Query
14:22
Take HIERARCHY queries to a HIGHER LEVEL
6:53
SQL and Database explained!
Рет қаралды 4,3 М.
Happy birthday to you by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 12 МЛН