Solving SQL Interview Query | Find Tree Node type using SQL

  Рет қаралды 28,435

techTFQ

techTFQ

Күн бұрын

Пікірлер: 59
@arjundev4908
@arjundev4908 2 жыл бұрын
Damn. This was asked in my ANZ interview which I couldn't answer this clearly. Thanks Toufiq for the clarity that you provided.
@shaikusman536
@shaikusman536 2 жыл бұрын
Awsome brother....Loved the way you approach problem statement....Respect from Bangalore,INDIA.
@techTFQ
@techTFQ 2 жыл бұрын
Thank you brother 🙏🏼
@chimadivine7715
@chimadivine7715 9 ай бұрын
I decided to solve it before watching your solution, and I actually solved it right. The difference is that, in the second 'when' statement, I didnt add: "p is not NULL" And I think it will still work correctly like that. I'm happy that my solution was same as the solution of a genius like you. Many thanks for this quality video!
@sandeepreddy9929
@sandeepreddy9929 Жыл бұрын
Thanks Toufiq for the effort you put in making these videos, I was actually waiting for a video on hierarchical queries. Another way if it helps others SELECT id, CASE WHEN CONNECT_BY_ISLEAF = 1 THEN 'Leaf' WHEN CONNECT_BY_ISLEAF = 0 AND LEVEL = 1 THEN 'Root' WHEN CONNECT_BY_ISLEAF = 0 AND LEVEL 1 THEN 'Inner' END typ from tree connect by prior id = p_id start with p_id IS NULL;
@arshadmohammed2346
@arshadmohammed2346 Жыл бұрын
way simple way to explain ! Thanks Taufiq
@venkatram9698
@venkatram9698 10 күн бұрын
I actually very impressed by your way of teaching please try solve more leet code problem
@muthu8025
@muthu8025 Жыл бұрын
The way you explained the problem I really stunned
@alisonhenley2551
@alisonhenley2551 Жыл бұрын
Excellent! Feeling a lot more prepared to take on interviews because of you!!!!
@suyash7450
@suyash7450 Жыл бұрын
Your explanation is just too good....
@greentechkey
@greentechkey Жыл бұрын
Great Explanation
@Zenoid_26
@Zenoid_26 Жыл бұрын
Thanks a lot for doing these kind of videos❤️
@fathimafarahna2633
@fathimafarahna2633 2 жыл бұрын
As always THE BEST
@techTFQ
@techTFQ 2 жыл бұрын
❤️❤️
@hariniharnath9932
@hariniharnath9932 Жыл бұрын
Well explained 👏. Made it easy
@lokeshmadiga6215
@lokeshmadiga6215 Жыл бұрын
Thank you bro for this solution !
@sse6
@sse6 6 ай бұрын
Great explanation
@dilipinamdar5523
@dilipinamdar5523 Жыл бұрын
Thanks a lot Taufiq, Please suggest books to read about MS SQL.
@satheeshkumarak6708
@satheeshkumarak6708 Жыл бұрын
Hello Sir @techTFQ, Can you make a video on working with JSON & Nested JSON data ?
@shaikhabib7799
@shaikhabib7799 2 жыл бұрын
Keep up the good work 🎉.
@vinaykumarpatnana
@vinaykumarpatnana Жыл бұрын
good class
@cococnk388
@cococnk388 Жыл бұрын
great thanks
@raitup00
@raitup00 2 жыл бұрын
Hi Taufiq, I think I have the next level of this excercise, actually is a real problem in a Pharmaceutical company. I was wondering if I can send you the the problem with extra complications and if you consider that the problem worth, would you mind solve it in a video? That would be nice
@avi8016
@avi8016 2 жыл бұрын
Thanks a lot Taufiq, One question it should be possible to approach the same problem via self join
@santhiv9029
@santhiv9029 Жыл бұрын
Hi,Your vedios are very useful and informative y don't you start oracle plsql topics also it will help to get logic how sql queries used to plsql as well
@Ajjeshh
@Ajjeshh Жыл бұрын
Thanks for the explanation . I have tried on my own and could you pls tell me what is the issue with the below code drop table if exists tree_node; create table tree_node (id integer, pid integer); insert into tree_node (id, pid ) values (1, null); insert into tree_node (id, pid) values (2, 1); insert into tree_node (id, pid) values (3,1 ); insert into tree_node (id, pid) values (4, 2); insert into tree_node (id, pid) values (5, 2); select *, case when pid is null then 'rootnode' when id not in (select pid from tree_node) then 'leaf_node' else 'inner_node' end as level from tree_node; Based on my case statement , it should print as "leaf_node" for records 3,4,5 . But It is not .. Any issue with my case statement ? Thanks.! This is the o/p i am getting id pid level 1 rootnode 2 1 inner_node 3 1 inner_node 4 2 inner_node 5 2 inner_node
@Iamabhay_
@Iamabhay_ Жыл бұрын
Sir, please-please makes a video on Database administrator vs Data science
@sujathav-rf4vt
@sujathav-rf4vt Жыл бұрын
when you will start your next batch ? and is there any offer for new year for our course ?
@nikhilavemuri955
@nikhilavemuri955 2 жыл бұрын
Hi Thoufiq, Waiting to join your online training. Please let me know when your next live training batch will get started.
@techTFQ
@techTFQ 2 жыл бұрын
Noted Nikhila, I’ll announce something by this month end
@nikhilavemuri955
@nikhilavemuri955 Жыл бұрын
@@techTFQ Sure, thank you! Thoufiq
@mdrimon3276
@mdrimon3276 Жыл бұрын
awesome!
@RAHUDAS
@RAHUDAS Жыл бұрын
Can we build custom function for same , kindly make video on custom functions
@CassStevens
@CassStevens Жыл бұрын
your solution is simpler than mine: select id, 'root' as type from tree where p_id is null union select distinct p_id as id, 'inner' as type from tree where p_id (select id from tree where p_id is null) and p_id is not null union select id, 'leaf' as type from tree where id not in (select distinct p_id from tree where p_id is not null) and p_id is not null
@hungry_panda9241
@hungry_panda9241 Жыл бұрын
Eagerly waiting for your reply
@rjc3872
@rjc3872 10 ай бұрын
Briiliant !!!
@sreekanth5059
@sreekanth5059 Жыл бұрын
Hi bro , Can you do a Video on ADF
@Tusharchitrakar
@Tusharchitrakar Жыл бұрын
Hi, firstly you have great pedagogical technique of explaining and kudos to you. Secondly, I was trying on my own before seeing your video and I used the exact same technique to derive the result but I wasn't happy for one reason. It's because of how the IN operator works: it does an entire table scan. For example, if I'm searching for id 3 in the p_id column, it will still keep searching till the end of the p_id even if it finds 3 earlier. Hence, one can imagine how inefficient this approach is for extremely large trees with thousands of nodes. I tried using an index too but still the query cost was not reduced. Is there something like a WHERE EXISTS that we can use where the search will stop as soon as I find the target (in this case 3 in p_id) instead of going till the end of the inner subquery table? Kindly give your input, thanks!
@rjc3872
@rjc3872 10 ай бұрын
Select Exists( Select p_id from tree where p_id=3 )...just giving an example , it will return true or false at the first instance it finds it ....
@Tusharchitrakar
@Tusharchitrakar 10 ай бұрын
@@rjc3872 thanks but my earlier understanding few months back was wrong. The SQL optimizer in the background does not necessarily do a full table scan and it depends on the specific DBMS engine being used
@GeekSP1
@GeekSP1 Жыл бұрын
@techTFQ in practice, why do we find the tree node type? i mean are there any use cases you can mention?? I appreciate spreading value
@DailyShit.
@DailyShit. Жыл бұрын
Hierarchical database models. Literally the oldest one.
@anilkumargovindan4138
@anilkumargovindan4138 Жыл бұрын
Need a solution for the below problem. Statement Input : Id val 1 3 2 1 3 2 Output Id val 1 1 1 1 1 1 2 1 3 1 3 1 Based on the value of the column 'val' the result set should be generated as shown
@prashantmhatre9225
@prashantmhatre9225 Жыл бұрын
Use recursive with clause
@AnandhiSeshadri
@AnandhiSeshadri Жыл бұрын
I have 3yrs experience in SQL server and I have changed testing domain for 8 months but I don't like testing again I want to change my domain SQL server. Can you please give some idea. Is SQL server is good in future and I have some career gap because of my baby and my baby has 2 month old now? It is the right time to look another job ? can you pls help me out?
@satyabharadwaj7779
@satyabharadwaj7779 Жыл бұрын
I have a doubt with the 'else' statement. Will it negate just the second 'when' statement or to both the 'when' statements?
@Soumchak96
@Soumchak96 Жыл бұрын
Else logic will only be applied if the earlier logic fails. Which means if it's not a root or an inner node then only it'll be a leaf node.
@satyabharadwaj7779
@satyabharadwaj7779 Жыл бұрын
@@Soumchak96 but we can use else for every when statement, isn't it? Here we have two when statements hence my doubt.
@rohitahuja999
@rohitahuja999 2 жыл бұрын
hi taufiq i am getting this error foreign key p_id = does not exist in the Tree table
@techTFQ
@techTFQ 2 жыл бұрын
U trying to solve it in leetcode is it? I thinking something wrong with leetcode today, even I faced some wierd error
@rohitahuja999
@rohitahuja999 2 жыл бұрын
@@techTFQ Hi do u have any video regarding any, all, some operator ?
@parveen8122
@parveen8122 2 жыл бұрын
Slightly different condition ======================== select id, case when p_id is null then "Root" when id not in (select distinct p_id from tree) then " Leaf " else " Inner" from tree
@techTFQ
@techTFQ 2 жыл бұрын
Nice 👍
@b_rizzle4808
@b_rizzle4808 2 жыл бұрын
i was thinking this too since the null exception is already covered in the first(root) case then it's not needed in the second(leaf) case; since it was already attributed in the first
@parveen8122
@parveen8122 2 жыл бұрын
@@b_rizzle4808 yes
@meenayegan6634
@meenayegan6634 Жыл бұрын
One small change, not in operator will return null values if null is present in the select list. change is: when id not in (select distinct p_id from tree where p_id is not null) then " Leaf "
@jabedhasan21
@jabedhasan21 Жыл бұрын
@@meenayegan6634 Nice Catch👍
@hungry_panda9241
@hungry_panda9241 Жыл бұрын
He hi bro how to contact you personally bro i want all SQL classes videos plz plz plz i will pay for that bro plz tell me how to contact you
@hungry_panda9241
@hungry_panda9241 Жыл бұрын
Bro plplz reply How can i contact you plz bro
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 28 МЛН
Lamborghini vs Smoke 😱
00:38
Topper Guild
Рет қаралды 54 МЛН
Deadpool family by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 5 МЛН
Practice SQL Interview Query | Big 4 Interview Question
14:47
How I use SQL as a Data Analyst
15:30
Luke Barousse
Рет қаралды 845 М.
REAL SQL Interview Problem | Hierarchical data in SQL
22:09
SQL Interview Query for Data Analyst
29:51
techTFQ
Рет қаралды 59 М.
Solving a tricky SQL Interview Query
19:24
techTFQ
Рет қаралды 50 М.
PayPal SQL Interview Problem (Level Hard) | Advanced SQL Problem
14:15
How to become a Data Analyst FAST (By 2025)
15:41
Rohan Adus
Рет қаралды 34 М.
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 28 МЛН