Тёмный

Part 2 SQL query to get organization hierarchy 

kudvenkat
Подписаться 835 тыс.
Просмотров 554 тыс.
50% 1

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 88   
@kids_world_2k
@kids_world_2k Год назад
You have posted this question 9 yrs before but i attended interview on 29 June 2023 where this question is asked. But i saw it now the next day..other wise i would have answered 😢
@Aman-x5g
@Aman-x5g 3 месяца назад
Yes
@siddhukr2643
@siddhukr2643 9 лет назад
I have 10,000 records of hierarchy data and if i go by this method it would have a serious impact on performance . So Sql has introduced a new datatype named hierarcyid which would give a better performance . Can you please post a video with above as example .
@fired_developer
@fired_developer 4 года назад
Thanks for the info
@mmmarketing5683
@mmmarketing5683 9 месяцев назад
my question here is how do u know were to add , * ( ) = @ . "" " is their a rule that i should know? could u help me pls
@tahirkamal1878
@tahirkamal1878 9 лет назад
We can do this with a simple Query, not necessairly a Recursive CTE, Can you show us a more concrete Example where only a CTE is possible, thank's :)
@Ds_Unangi
@Ds_Unangi 7 лет назад
The way you break the problem into pieces and then one by one solve them....its really great...really impressed by your work..... keep it up. god bless you :D
@zaheershaikh6834
@zaheershaikh6834 9 лет назад
Good tutorials... We can achieve the hierarchy of the organization with simple query also... Example here is select A.EMPLOYEEID,A.ENAME,A.DOB,A.GENDER,A.DESIGNATION, A.SALARY, Z.ENAME AS MANAGER FROM employees a inner join employees z on a.managerid = z.employeeid go select A.EMPLOYEEID,A.ENAME,A.DOB,A.GENDER,A.DESIGNATION, A.SALARY, ISNULL(Z.ENAME, 'NO BOSS') AS MANAGER FROM employees a left join employees z on a.managerid = z.employeeid
@bluesage1528
@bluesage1528 Год назад
Great! Thank you👌
@raghuuvamsii
@raghuuvamsii 4 года назад
Excellent sir, I'm a big of fan of your way of teaching. Getting the knowledge effectively is good thing but sharing that is great thing.
@nanani1729
@nanani1729 4 года назад
Hi @kudvenkat, If there is Union All, for every level up, David Record has to be appended once correct? There must be some duplicates atleast? But your output doesn't have any duplicates. Can you let me if I'm thinking correct, will there be any duplicates at all?
@alihameed2457
@alihameed2457 7 лет назад
Hello Venkat, i am a big fan of you. You really are a great person indeed. I just pray may ALLAH the almighty shower HIS Countless blessings upon you. Aameen
@bipin1042
@bipin1042 6 лет назад
In case of row number... . For getting the nth highest salary.. We can use distinct instead of top 1... I think this will work..
@kamleshnakade2277
@kamleshnakade2277 8 лет назад
Great Work Venkat. Really Impressed by the way of representation and examples,which are very clear to understand. Thanks a ton!!
@Csharp-video-tutorialsBlogspot
+Kamlesh Nakade Thank you for the feedback. This means a lot. Very pleased you found these videos useful. Dot Net & SQL Server training videos to help you become a web developer ru-vid.complaylists?view=1&sort=dd Download videos for offline viewing www.pragimtech.com/Order.aspx Slides, Code Samples & Text Version of the videos can be found on my blog csharp-video-tutorials.blogspot.com Tips to effectively use our youtube channel ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-y780MwhY70s.html To receive alerts, when new videos are uploaded, please subscribe to our channel ru-vid.com If you like these videos, please click on the THUMBS UP button below the video May I request you to please share the link with your friends who you think would also benefit from them To teach is to learn Thanks Venkat
@alwaysbehappy1337
@alwaysbehappy1337 5 лет назад
I got an error :- The statement terminated. The maximum recursion 100 has been exhausted before statement completion. Please Explain it.
@tk200895
@tk200895 4 года назад
I am also getting the same error
@Boomstck
@Boomstck 4 года назад
Sounds like you created an infinite loop, unless if the query you are running is different from this tutorial. If this is a different query, then you can solve this issue by using OPTION (MAXRECURSION 0)
@Adinasa2
@Adinasa2 Год назад
One of the most complex queries i have ever seen! great work!
@vishwanathmali9008
@vishwanathmali9008 8 лет назад
nice venkat sir it is really great job for needy people god bless u
@ymtan
@ymtan 10 лет назад
Sir, can you kindly explain how the second query after the UNION ALL within the EmployeeCTE works because I am finding the recursive CTE difficult to understand even after watching the Part 51 Recursive CTE
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 10 лет назад
Sure, I think it would be easy to explain this in a video rather in text. Will try to record and upload a video in a few days. Thank you for your patience. Good Luck.
@vinitsawant8104
@vinitsawant8104 Год назад
For MySQL with recursive cte (EmployeeID, EmployeeName, ManagerID) as ( select EmployeeID, EmployeeName, ManagerID from employeestemp where EmployeeID = 5 union all select p.EmployeeID, p.EmployeeName, p.ManagerID from employeestemp p inner join cte on p.ManagerID = cte.EmployeeID ) Select E1.EmployeeName, IFNULL(E2.EmployeeName, 'No Boss') as ManagerName From cte E1 LEFT Join cte E2 ON E1.ManagerID = E2.EmployeeId;
@priyaranjandas762
@priyaranjandas762 6 лет назад
God bless you I pray to my Lord full fill your every problem.
@stuti.sharma.ranchi
@stuti.sharma.ranchi 2 года назад
This is a great case! I went through self-join, CTE, and recursive CTE videos, and last but not least this interview case. Very comprehensive understanding of these concepts now. Thank you!
@ukkashs444
@ukkashs444 2 года назад
Where are you working frd??
@akfsf00543
@akfsf00543 3 года назад
SELECT EMPLOYEEID, EMPLOYEENAME, (SELECT EMPLOYEENAME FROM EMPLOYEES WHERE EMPLOYEEID = A.MANAGERID) AS MANAGER from Employees AS A;
@Arvindkumar-wu3gj
@Arvindkumar-wu3gj 7 лет назад
Hi Venkat, below query is not working in Declare @ID int ; Set @ID = 7; WITH EmployeeCTE AS ( Select e.EmployeeId, e.EmployeeName, e.ManagerID From Employees e Where EmployeeId = @ID UNION ALL Select Employees.EmployeeId , Employees.EmployeeName, Employees.ManagerID From Employees JOIN EmployeeCTE ON Employees.EmployeeId = EmployeeCTE.ManagerID ) Select E1.EmployeeName, ISNULL(E2.EmployeeName, 'No Boss') as ManagerName From EmployeeCTE E1 inner Join EmployeeCTE E2 ON E1.ManagerID = E2.EmployeeId In MSSQL 2012
@nikhilkumarchaudhary9593
@nikhilkumarchaudhary9593 4 года назад
can anyone help what should be the query, if desired output ll be in a single column like----> David Tom Steve Ben
@raghuuvamsii
@raghuuvamsii 4 года назад
@kudvenkat Sir, why don't you provide carrer advice us as a successful person. I mean how to make plan to become successful developer in .net from fresher level.
@neemkarolimaharajji-j6t
@neemkarolimaharajji-j6t 2 года назад
sir aapne set and declare k baad 0id likha h ya kuch or? kuch smjh nhi aara?
@kvclips7
@kvclips7 3 года назад
Input Col1 A B C D Output Col1 Col2 A. B B. C C. D D. A Can you please help me to find out the script for the above requirements
@hirajijadhav3135
@hirajijadhav3135 7 лет назад
Hi venkat sir recently I attended interview and there interviewer asked me SQL query as there are two tables item and item Rate item table consist of item id Item Name 1. Parker 2. Marie 3. Good Day 4. Monaco item Rate consist of ItemId ItemRate 1. 5 3. 20 and Query was. select I.iemName from item I left join ItemRate R on I.itemId!=R.itemId where R.itemRate>5 what is the output of above query please explain
@rajeshgangineni6333
@rajeshgangineni6333 7 лет назад
Hiraji Jadhav Good day
@ganirban82
@ganirban82 7 лет назад
Hi Hiraji Jadhav, I try to give the answer. It is an actually inner joins with a condition . Answer is "Marie, Good Day, Monaco" item names. Please correct me, if i am wrong. Regards,
@VinodKashyap-jb4ny
@VinodKashyap-jb4ny 5 лет назад
u wil get good day
@deepakvashishtha9669
@deepakvashishtha9669 Год назад
The output will be:- Parker Marie Monaco Answer Explanation:- These two tables has left join and not equal condition so the below query gives the 6 results on not equal condition select I.itemName from item I left join ItemRate R on I.itemId!=R.itemId output:- ItemName ICode RCode Rate Parker 1 3 20 Marie 2 1 5 Marie 2 3 20 Good Day 3 1 5 Monaco 4 1 5 Monaco 4 3 20 And in the last query has where clause rate>5 so the final query output will be Parker Marie Monaco Tx, -Deepak Vashishtha
@anbumani6083
@anbumani6083 5 лет назад
OK i got it. When the query before union runs already the CTE has one row. Then after union query, it starts processing from that available first row. Am i correct? Thanks.
@prattipatinaveena6187
@prattipatinaveena6187 Год назад
Sir I have one doubt.if I am passing anyone id in the company I want only ceo name
@rickymartin8759
@rickymartin8759 7 лет назад
best sql video in youtube. Thanks !
@vishalbtile
@vishalbtile 8 лет назад
"Except org hierarchy where we can use recursive CTE? " was one of my interview Q being asked to me. can you pl tell??
@shaiksajid1096
@shaiksajid1096 5 лет назад
मराठी वादळ - छत्रपती शिवाजी महाराजI'm
@rajendrakushwaha7185
@rajendrakushwaha7185 5 лет назад
As a fresher for interview is it important to know about sql server . As i have college placement for sql developer? how to preprare for interview and which portion
@nikhilkumarchaudhary9593
@nikhilkumarchaudhary9593 4 года назад
i am facing error of---> Must declare the scalar variable "@ID".
@mattyork5143
@mattyork5143 6 лет назад
Hello..how to create a list of managers and their employees given the fact that each manager has more than one employee ? Thanks
@sunmeetsingh8136
@sunmeetsingh8136 2 года назад
Awesome video sir. Where can we get the scripts for the tables that you use?
@sumitjangir48
@sumitjangir48 8 лет назад
Hello Sir, I have a doubt, This result can be get by following query select a.Employeename,isnull(b.employeename,'No boss') as manager from Employees a left join Employees b on a.ManagerID = b.EmployeeId then why we use CTE or recursive query?
@sumitjangir48
@sumitjangir48 8 лет назад
Got it. Thanks Man :)
@riyankabhowmick697
@riyankabhowmick697 7 лет назад
Really impressive...
@pastorey2
@pastorey2 10 лет назад
I upgraded to sql 12, now I get an error whener try to use the Keyword with in the command WITH RESULT AS in the CTE,
@BornDude25
@BornDude25 6 лет назад
use ;with Result as .You were missing a ';'
@harshvardhandewari8147
@harshvardhandewari8147 6 лет назад
Why is UNION ALL used, what will happen if UNION is used instead, I want to know the logic behing using Union ALL , thank you.
@gaayathiri5514
@gaayathiri5514 5 лет назад
UNION merges the contents of two structurally-compatible tables into a single combined table. The difference between UNION and UNION ALL is that UNION will ignore the duplicate records whereas UNION ALL will include duplicate records. It is important to note that the performance of UNION ALL will typically be better than UNION, since UNION requires the server to do the additional work of removing any duplicates. So, in cases where is is certain that there will not be any duplicates, or where having duplicates is not a problem, use of UNION ALL would be recommended for performance reasons.
@dipintigupta9777
@dipintigupta9777 5 лет назад
can be possible Sql Query convert in hierarchy
@davidramirez3322
@davidramirez3322 5 лет назад
Thnks Venkat, Can't stop watchig your work and great tutorials.
@makdatesfa4337
@makdatesfa4337 9 лет назад
Thank you so much but what is ITT in SQL server.
@SuperJV4x
@SuperJV4x 5 лет назад
I need to do this from top down, not bottom up as in this example (i.e. give the manager and get all the subtrees of employees)
@androidsavior
@androidsavior 5 лет назад
Same here, Did you do it ?
@FlareSoul69
@FlareSoul69 9 лет назад
Loved this real world SQL application!! Please make more SQL videos like this!
@anilkumarreddy2769
@anilkumarreddy2769 2 года назад
impeccable explanation Mr.Venkat
@SanjeevVermasanjeevr0728
@SanjeevVermasanjeevr0728 8 лет назад
your every video is very easy to under stand and really very help full.
@BuyLAHouse888
@BuyLAHouse888 4 года назад
Thank you sooooooo much for great resourse made.
@leonardchamin
@leonardchamin 5 лет назад
such a great video. Thank you
@alokdas6628
@alokdas6628 6 лет назад
Hi, I faced the similar kind of question in an interview but the requirement was little different. If you pass the id as 7 which is David's id you should get the output of your last manager which is ben's record only. How we can do that?
@elishadeshawn2599
@elishadeshawn2599 3 года назад
pro tip: watch movies at Flixzone. I've been using it for watching lots of of movies lately.
@brodiegianni235
@brodiegianni235 3 года назад
@Elisha Deshawn yea, have been watching on flixzone for since december myself :D
@sabyasachisahu7663
@sabyasachisahu7663 8 лет назад
Hi Venkat, One question I do have, if I want to join 10 tables then how many minimum "Join" statements I can use ?
@gkmishra2009
@gkmishra2009 5 лет назад
Give video on how consume web api in wcf
@kleberoliveira5618
@kleberoliveira5618 3 года назад
If I have two super Boss???
@travelling_owl
@travelling_owl 7 лет назад
Query with out cte:- select e1.empName ,e2.empName as ManagerName from emp e1 Left join emp e2 on e1.ManagerId=e2.empid;
@kehtahaipalpal
@kehtahaipalpal 7 лет назад
Venkat's video gives us a hierarchy for a particular individual at a time. Your query won't do that.
@travelling_owl
@travelling_owl 7 лет назад
Rohan Sawant I am aware of that. but beginners will find it difficult to understand. so i posted the simple query. thanks again😇
@kehtahaipalpal
@kehtahaipalpal 7 лет назад
Amitanshu Mishra ohhh ok.. got you.. :-)
@frankrobert9199
@frankrobert9199 2 года назад
Best sql tutorial I have seen.
@devarakondasankararao3802
@devarakondasankararao3802 5 лет назад
I like this video much More
@RakeshRanjanSingh-23
@RakeshRanjanSingh-23 6 лет назад
Sir... You are great... Thank you...
@pakistani8907
@pakistani8907 8 лет назад
Why is @ID set to 7?
@mario17-t34
@mario17-t34 4 года назад
Thanks much V!!
@syedmohdnaqizaidi5924
@syedmohdnaqizaidi5924 8 лет назад
very useful
@safiulhaque3736
@safiulhaque3736 7 лет назад
Great job thanks
@krismaly6300
@krismaly6300 10 лет назад
Good video
@khadarbabus9962
@khadarbabus9962 10 лет назад
sir, One Interview qustion i Faced ......find third highest number in arrays without using sorting..... and values will be give at run time...values must be distinct..no duplicate values... this is one of interview question 
@leelay4749
@leelay4749 4 года назад
I was asked below question today in #Microsoft technical interview. There are 5 micro services writing telemetry to Log Table Log schema includes the following. a. SourceID b. Message Description c. Severity d. Timestamp. Logs written to Log Table are asynchronous. configure an alert and notification to be sent when more than 5 severity 3 logs are written in a 5 mins window. Basically the question is, result set should contain a alert record of a particular sourceID whose severity is 3 and occurred more than 5 times and also the occurances with in 5 min window. Can anyone help me with the approach and query for this question?
@ulysses1904
@ulysses1904 6 лет назад
Great stuff but please stop saying "Superboss". I have never in my life heard anyone use that word and it gets repeated endlessly in these videos. How about "CEO" or "Owner" or "Department Head".
Далее
Part 3   How does a recursive CTE work
8:12
Просмотров 313 тыс.
Part 1   How to find nth highest salary in sql
11:45
Просмотров 1,9 млн
КОТЯТА В ОПАСНОСТИ?#cat
00:36
Просмотров 1,8 млн
Свадьба Раяна Асланбекова ❤️
00:12
REAL SQL Interview Problem | Hierarchical data in SQL
22:09
Take HIERARCHY queries to a HIGHER LEVEL
6:53
Просмотров 4,4 тыс.
How do SQL Indexes Work
12:12
Просмотров 621 тыс.
54 How to use multiple CTE in SQL Server
7:44
Просмотров 4 тыс.