Congratulations monika on clearing your interview! 🎉 I'm currently preparing for a similar interview for an SQL Server position and was wondering if you could share any tips or a list of the questions you were asked? Your insight would be incredibly helpful. Thank you so much in advance!
Its not at all a tutorial video its a master or an expert explaining. You dont explain the approach or idea you just make everything clear in all the concepts you explain. Awesome
Just want to say first, this channel is invaluable. Thought I'd offer up a solution for problem 7 that's a little more concise. This assumes that as in the example data, consecutive increasing id numbers correspond to consecutive increasing dates, with each id number corresponding to a unique day. The approach is: 1. Remove records with temperatures above 0 using a WHERE statement. 2. Of the remaining rows check each one to see if it is part of a consecutive triplet-- we could use the date column for this with a specialized date function, but it's easier to use the id column, if the assumption stated above is true 3. A row in a consecutive triplet will meet one of three criteria: Either A-- the two leading rows have consecutive id numbers, B. The lagging row and the leading row both have a consecutive id, or C. The two lagging rows have consecutive ids. 4. The CASE statement checking for these criteria are then packaged in a subquery returning just the id of qualifying rows. 5. The main query uses IN to return only rows having the ids returned by the subquery. SELECT * FROM weather WHERE id IN (SELECT CASE WHEN id + 1 = (LEAD(id) OVER ()) AND id + 2 = (LEAD(id, 2) OVER ()) OR id - 1 = (LAG(id) OVER ()) AND id + 1 = (LEAD(id) OVER ()) OR id - 1 = (LAG(id) OVER ()) AND id - 2 = (LAG(id, 2) OVER ()) THEN id END as check FROM weather WHERE temperature < 0)
Great video, for #4. Since the same doctor will not have different specialist, we can just compare hospital names and specialist and it will make sure we do not have the same doctor being compared with him/her self.
Hi Rodney, Thank you for such kind feedback 🙏🏼 Am so glad this could help you .. I feel if you keep spending time to learn Sql every day for 1-2hrs, I am sure within a month you would be very comfortable and you should be able to solve most Sql queries .. Just needs time, patience and belief that you can do it .. keep the faith and I am sure you will master SQL soon..
Rodney does not respond to simple queries now. He's in an advanced query mode now. Here is the query that might initiate a response from Rodney: - Hey Rodney, does your existence on the Planet Earth been achieved, now that you have questioned on a YT video and also got an interesting and encouraging reply from the YT channel admin which might have initiated you to spend more than 2 hours o a daily basis with endless belief that you can achieve the impossible and with the time and patience you had in your hands, you spent the time wisely and now have reached the Query Nirvana in any QL?
Watching this video in 2024 as a part of my interview preparation. Great videos!!! Here is my approach to login_details question using CTEs with cte as( select *, LEAD(user_name) over(order by login_id) lead1, LEAD(user_name,2) over(order by login_id) lead2 from [dbo].[login_details]) select distinct(user_name) from cte where user_name = lead1 and user_name = lead2
Hi, Thank you for your time and effort. Please continue these complex queries as a series. Thank you once again, i am getting a hold on sql after watching your videos especially on CTE's and sub queries which plays a major role in getting required outcome.
Thank you Sreeram 🙏🏼 I am so happy to know you have benefited from my video’s .. Yeah will continue making more such videos. Tomorrow will be posting a video about a particular complex Sql query so hopefully you will like that one too..
@@techTFQ quick question, does "select d1.* from doctors d1 JOIN doctors d2 ..." works exactly than "select d1.* from doctors d1 INNER JOIN doctors d2..."? Thank you in advance
I’ve finally watched the whole thing and this is definitely my favorite kind of your videos. I learn the most by watching you and hearing your thought process and the nice bonus is then I can go and download your script, create an identical table and then go try and do it myself. That’s where I learn the most, bc I can try my own ideas and just make little changes and see if that completely throws an error and then I try and understand why that error was thrown so I can avoid that problem in the future. Thank you again for your help and your time investment. Over 113K views on here shows I am not the only one this is helping. 🙏🏻 Many blessings to you and your family, TFQ
Thank you so very much Laura 🙏 I am really impressed by the way you are trying to use this resource to learn and practice SQL. Very happy to be contributing to your learning too.. Happy learning and wishing you all the very best :)
@@techTFQ And it’s working because I repeated the course on joins and also intermediate sql on DataCamp and after watching your videos on key topics, I was able to make significant progress. Their lectures are very short and the material was completely new to me the first time. Also I was trying to take too many classes and not allowing time to absorb the information. Watching your more detailed explanations helped me a lot and now I believe I’ll be able to solve most of the queries you’ve posted. I’ve created all of your tables in my database so that I can make sure of that. I have a deadline to meet to pivot my career and so I am a little in rush mode and I’m so glad I found your videos when I did because they are exactly what I needed to supplement those courses. Again, I realize how much time and thought went into this and as the mascot I’d like to speak for all of your viewers and offer our appreciation for all of it 🙏🏻😀
I failed a DA interview because I was not able to solve a question similar to Query 9. But Now I am smarter than before because of you. Thanks a lot. Really very useful content
Every other SQL tutorial youtuber just shares the basics which is good , but going through these examples and approach is really well thought of.. Appreciate the work! Thank you
Thank you!!! I discovered Process Query Language (PQL) that uses Lead & Lag times (different structure) and the concepts really help with understanding.
Nothing like your contents on this whole TH-cam. Genuinely appreciate your efforts in churning out such beneficial n functional contents🙏Also, the blog is just amazing. Clean, clear, authentic. Kudos to your efforts n intention👏🙌
FYI - I'm doing the exercises using MySQL (using POPSQL) and for query 5, using the line INSERT INTO login_details values(113, 'James', current_date+6); was giving me an error because it was trying to store 2021-11-32, so I had to change the line to INSERT INTO login_details values(113, 'James', DATE_ADD(current_date, INTERVAL 6 DAY)); Great series of vidz, I'm learning so much and my head is starting to get into the SQL groove.
This is by far the best video for understanding SQL queries, the way you have explained by running small parts first and than solving to get the end output and also the pace was very much decent. Thanks man ! and please continue to make more of such videos :)
Was glad to see your "Download script"...at least for the 1st example also worked with SQLite. It also needed the rowid change for the SELECT. SQLite is stand alone and doesn't require a server.
select * from( select *,max(salary) over (partition by dept_name ) as max_salary, min(salary) over (partition by dept_name ) as min_salary from employee)x where salary in (x.max_salary,x.min_salary) - I tried this approach for Q3
OMG, this was my reaction when you cleared my doubt on lead and lag... I don't know whether you're a good employee or not but YOU'RE AN AMAZING TEACHER. I regret not taking your intermediate live sessions. Do tell me if you're starting a next batch on intermediate queries.
Hi TFQ, For Query 5 : From the login_details table, fetch the users who logged in consecutively 3 or more times. Instead of lead function we can use Rank as well ryt. This also gives correct output. Below is my Query and please let me know if this is the right way to use Rank function or not. select distinct user_name from (select *,rank() over(partition by user_name order by login_date ) as rnk from login_details ) where rnk >=3 ;
as a mac user, your videos were mashallah very helpful, especially the way you think gives a practical approach to finding solutions. As a beginner i find it very nice thanks brother and keep up good work.
Thanks mitra khup chan shikavtoy ,mala tuza blog madhun khup kahi shikayla milale ,dhnaywad..!! select emp_id,emp_name,dept_name,salary from ( select *, min(salary) over (partition by dept_name) as min_salary, max(salary) over (partition by dept_name) as max_salary from employee ) as x where salary =x.min_salary or salary =x.max_salary
I think in the 4th exercise (query a) there is no need to put the a.ID b.ID because the condition d1.speciality d2.speciality automatically restrict that record from coming
Totally agree with many of the viewers comments. You are the best SQL guru I have seen on TH-cam. Wish you were our teacher in college when we learned these without this much clarity.Hats off to dedication and hard work..👏👌
Thanks a lot, have not touch SQL around 3-4 years after school, a new task requires me to start from fresh. Spending 5 hours on one query joining 5 tables is REALLY not fun and frustrated :(
Loved your step-by-step approach towards solving complex SQL queries. Hope to see more similar videos in the coming days and really appreciate your hard work in making such a helpful content.
Hi there, thank you so much for sharing your knowledge. I am self learning, and your examples have helped me so much with the advanced concepts. Thank you!!!!!!
I subscribed to your channel while you were still explaining query #2 Your speed and way of explaining as well as the examples you picked are SPOT ON ! WE NEED MORE VIDEOS, QUERIES and EXAMPLES FROM YOU !! PLEASE POST MORE VIDEOS... THANK YOU !!
Thank you so much for sharing such an extreme knowledge with us. Now I'm able to get some idea on the complex queries and practicsing as well. All your videos are very much helpful for me. Thanks a lot for taking so much effort and time to make these videos. Easy to understand and grasp the hidden concepts practically. Plz do share more on window functions queries used in real-time. God Bless You.👍🤝
TechTFQ: super great job. This is high quality knowledge sharing. Like you said knowing the different clauses and expressions doesn’t mean being able to apply them to concrete queries. Keep these great tutorials coming please. If you could increase the degree of complexity with aggregate functions that’d be super appreciated. Can’t wait to watch your next vids. Got yourself a new subscriber. Thanks a lot.
Thank you Mathieu 🙏🏼 So glad to read this comment.. will consider your suggestion to include more complexity in the future.. glad you are subscribed ☺️
Your teaching methodology is superb.... I have shared it with my husband who is looking for a course in SQL. He too found it very useful, easy to understand.
Fantastic..This helps infrastructure oriented DB engineers like us to quick assist customers with query tuning or performance tasks. Thanks for making time to share this dude.
Thank you for this video. It's detailed and well explained. Hope to see more! I used Postgre to run the queries and it was successful, but when I tried the query for duplicate records on MSSQL, it returned an error saying (the ORDER BY clause is invalid in views...) Kindly suggest what to do.
Thank you for liking the content 🙏🏼 These queries were written in PostgreSQL but I will soon update my blog to have corresponding queries in MySQL and Microsoft SQL server also .. may be in couple of weeks
Nice examples.. I feel writing below query for finding duplicate records is bit easier . Select user_id,user_name,email from (Select user_name,count(user_name) un from users group by user_name) asd Where asd.un>1
This channel is very good for learning SQL, the way of explaining and displaying content is superb. If this channel could give us videos on interview questions of top companies then we won't be needing to go to other websites.
Hi Ashish , Thank you for such kind words 🙏🏼 It’s so nice to see you have liked my work and it is beneficial to you 🙂 As for interview questions, I will plan it out in the near future..
Question 6 ) select *, case when id % 2 = 0 and id < (lead(id) over(order by id)) then lag(student_name) over(order by id) when id % 2 0 and id < (lead(id) over(order by id)) then lead(student_name) over(order by id) else student_name end from students;
Man, this tutorial is really awesome!!! Thank you so much for your detailed explanation. It will be very great if you post more videos on solving complex queries!!!
TFQ, I predict greatness for your channel with content like this. Seriously, you stand apart because your explanations are so clear and you put so much time and effort forward for your videos and this shows. I think I speak for all your subscribers when I say thank you, thank you. We SO appreciate all of your hard work. 100K will be in your rear view mirror before too long, my friend. 👍🏻😊
I also want to add that I’m so happy right now because I was having troubles with a Leetcode query I was trying to solve and after your terrific explanation about self-joins, which I’d struggled a bit with in the past, I was able to go right back there and quickly solve it. I don’t know if you’re interested in teaching, but you’re a natural at it. Thank you so much! I now understand something in a few minutes that had really confused me in the past! Blessings to you and yours for a wonderful November, TFQ!
Thank you thank you Laura 🙏🏼 🙏🏼 It’s so true that each of these videos take a lot of effort to make but getting this kind of feedback makes everything worth it.. I am short of words to thank you for your support and I just wish you success in everything you do.. I am also so glad to hear that you could apply the teachings in this video to solve leetcode queries.. I feel overwhelmed by this feedback .. Thank you once again and have a great start to the month.. 🙏🏼☺️
@@techTFQ I used to have an art blog and it took quite a bit of effort, so I can only imagine the time to film, plan etc., but your explanations simplify complex operations so well that I feel your efforts are bound to bear fruit. Look how much your channel has grown already! You’re doing great, and we thank you again. 🙏🏻👍🏻
Liked before finishing it, useful videos For question#1 used CTE what do you think about it? with duplicaterecords as ( select *, count(user_name) as namecount from users group by user_name having namecount>1 ) select user_id, user_name, email from duplicaterecords;
Just few hours ago I posted video about JOINS. In that I have written a query at the end where I joins multiple table using different type of joins. Do check that video out. link below: th-cam.com/video/0OQJDd3QqQM/w-d-xo.html
you literally make the best videos!! please keep making more with more queries and performance tuning tricks and interview focused complex queries. Thank you so much for your amazing content!
Hi I really enjoyed this video. I was wondering, is it possible to also use the row_number windows function to solve the third example on login frequency?
Hi Solomon, Yes you can write a query using row_number window function to solve this as well. In fact, I have posted a video on my channel giving a generic query using row number window function to fetch any no of consecutive records from a table. You can watch that video from the link below: th-cam.com/video/8p_OzqIJ_p4/w-d-xo.html
The best material for SQL in TH-cam that I have sawn, amazing blog as well, please go on such queries, which will really help many learners including myself.
Sir, could you please make a video on indexes and views and interview questions based on that also.. It would be really helpful and all your videos are great.. Keep rocking❤️
Thank you so much for your kind words 🙏🏼 So glad you liked my videos . Surely will consider your suggestions, let me see when I can cover these topics too..
Excellent. Quick question on the temperature query, would an alternative query using self join be more concise? Rather than nested case statement. Keep up the great work.
Thanks Ed for liking the content 🙏🏼 You can always write a query on many different ways and using self join may be an option for this kind of query but if you wish to fetch any no of consecutive records then I have made another video covering it. I’ll leave a link to it below.. have a look at this generic solution as well. th-cam.com/video/8p_OzqIJ_p4/w-d-xo.html
Very well explained video for learners like me who face problems with complex queries. Request you to provide more new queries and some source where I can practice to brush my basic SQL queries as well.
Thank you Thoufiq for this video, I’m anted to find out if writing the query for the records users who logged in 3 or more times shouldn’t have been Select distinct(user_name) From ( Select *, Case when user_name = lead(user_name, 3) over(order by login_id) Then username Else null End as repeated_users From login_details) x Where x.repeated_users is not null;
Your explanations are kind of addictive :) Can’t stop or skip in between , The use cases are very well descriptive , Hats off to your amazing effort ! Finally managed to stop at 12:10 am Central European Time ;)
Most difficult thing in SQL is the point where something is null. In other languages where the approach is more structural, in SQL this null value can blow up your query to become a Stephen King book.
Thanks for this video. It was indeed a good practice for me. Just thought, for the consecutive login problem, i tried a different way may be this is a traditional way of writing the query assuming the login_id definition as identity(100,1) column select distinct l1.user_name from login l1 join login l2 on l1.user_name = l2.username and l2.login_id = l1.login_id +1 join login l3 on l2.user_name = l3.user_name and l3.login_id = l2.login_id+1
After going through this I realised how much we can do with SQL. I thought I knew SQL but now I know there's a lot to learn.
Exactly my thoughts.....but i have my interviews soon 😭😭
I have cleared one of my interviews with top MNC company because of this training video. Thank you so much.
Amazing … congratulations Mounika 💐
I am so glad to read this comment ☺️🙏🏼
Congratulations monika on clearing your interview! 🎉 I'm currently preparing for a similar interview for an SQL Server position and was wondering if you could share any tips or a list of the questions you were asked? Your insight would be incredibly helpful.
Thank you so much in advance!
15:27 the first condition d1.id d2.id is redundant since its more narrow than d1.speciality d2.speciality
Its not at all a tutorial video its a master or an expert explaining. You dont explain the approach or idea you just make everything clear in all the concepts you explain.
Awesome
you are so well spoken! no unnecessary talk, straight to the point, in depth explanation!
Thank you Saidul. glad you liked it :)
Who else thought that they knew SQL until they came across this and then realized that they have a long way to go?😅
Me today😂😂
I am one of them😢
Just want to say first, this channel is invaluable.
Thought I'd offer up a solution for problem 7 that's a little more concise. This assumes that as in the example data, consecutive increasing id numbers correspond to consecutive increasing dates, with each id number corresponding to a unique day.
The approach is:
1. Remove records with temperatures above 0 using a WHERE statement.
2. Of the remaining rows check each one to see if it is part of a consecutive triplet-- we could use the date column for this with a specialized date function, but it's easier to use the id column, if the assumption stated above is true
3. A row in a consecutive triplet will meet one of three criteria: Either A-- the two leading rows have consecutive id numbers, B. The lagging row and the leading row both have a consecutive id, or C. The two lagging rows have consecutive ids.
4. The CASE statement checking for these criteria are then packaged in a subquery returning just the id of qualifying rows.
5. The main query uses IN to return only rows having the ids returned by the subquery.
SELECT *
FROM weather
WHERE id IN
(SELECT
CASE
WHEN id + 1 = (LEAD(id) OVER ()) AND id + 2 = (LEAD(id, 2) OVER ())
OR id - 1 = (LAG(id) OVER ()) AND id + 1 = (LEAD(id) OVER ())
OR id - 1 = (LAG(id) OVER ()) AND id - 2 = (LAG(id, 2) OVER ())
THEN id
END as check
FROM weather
WHERE temperature < 0)
Thank you so much sir ,I watched your video and able to solve multiple query in interview,now I'm selected 😊 as software developer trainee
Anyone starting out or wishing to improve there SQL , this is definitely for us. Great job👏👏👏
Great video, for #4. Since the same doctor will not have different specialist, we can just compare hospital names and specialist and it will make sure we do not have the same doctor being compared with him/her self.
I wish i could be as good as you at SQL, am struggling, God help me, thank you for such a well explained tutorial with amazing dedicastion.
Hi Rodney,
Thank you for such kind feedback 🙏🏼
Am so glad this could help you ..
I feel if you keep spending time to learn Sql every day for 1-2hrs, I am sure within a month you would be very comfortable and you should be able to solve most Sql queries ..
Just needs time, patience and belief that you can do it .. keep the faith and I am sure you will master SQL soon..
How are you doing at SQL now???
How your sql now?
Rodney does not respond to simple queries now. He's in an advanced query mode now.
Here is the query that might initiate a response from Rodney: - Hey Rodney, does your existence on the Planet Earth been achieved, now that you have questioned on a YT video and also got an interesting and encouraging reply from the YT channel admin which might have initiated you to spend more than 2 hours o a daily basis with endless belief that you can achieve the impossible and with the time and patience you had in your hands, you spent the time wisely and now have reached the Query Nirvana in any QL?
Too funny man 😅
Bravo to you if you get the desired response 😬
Watching this video in 2024 as a part of my interview preparation. Great videos!!!
Here is my approach to login_details question using CTEs
with cte as(
select *, LEAD(user_name) over(order by login_id) lead1,
LEAD(user_name,2) over(order by login_id) lead2
from [dbo].[login_details])
select distinct(user_name)
from cte where user_name = lead1 and user_name = lead2
Hi, Thank you for your time and effort. Please continue these complex queries as a series. Thank you once again, i am getting a hold on sql after watching your videos especially on CTE's and sub queries which plays a major role in getting required outcome.
Thank you Sreeram 🙏🏼
I am so happy to know you have benefited from my video’s ..
Yeah will continue making more such videos.
Tomorrow will be posting a video about a particular complex Sql query so hopefully you will like that one too..
@@techTFQ quick question, does "select d1.* from doctors d1 JOIN doctors d2 ..." works exactly than "select d1.* from doctors d1 INNER JOIN doctors d2..."? Thank you in advance
I have sent you a request on LinkedIn.
@@MariadelCarmen-gj8ulyes
@@Devasinger-0070thank you so much!
This is the only SQL related video on TH-cam I have watched throughout without clicking the skip button
You are the greatest SQL teacher i have seen. Period
haha Thank you Sahil :)
Also finished practicing coding .Now feeling hell lot of confident in my pursuit of data analyst
That’s great buddy
I’ve finally watched the whole thing and this is definitely my favorite kind of your videos. I learn the most by watching you and hearing your thought process and the nice bonus is then I can go and download your script, create an identical table and then go try and do it myself. That’s where I learn the most, bc I can try my own ideas and just make little changes and see if that completely throws an error and then I try and understand why that error was thrown so I can avoid that problem in the future. Thank you again for your help and your time investment. Over 113K views on here shows I am not the only one this is helping. 🙏🏻 Many blessings to you and your family, TFQ
Thank you so very much Laura 🙏
I am really impressed by the way you are trying to use this resource to learn and practice SQL. Very happy to be contributing to your learning too..
Happy learning and wishing you all the very best :)
@@techTFQ And it’s working because I repeated the course on joins and also intermediate sql on DataCamp and after watching your videos on key topics, I was able to make significant progress. Their lectures are very short and the material was completely new to me the first time. Also I was trying to take too many classes and not allowing time to absorb the information. Watching your more detailed explanations helped me a lot and now I believe I’ll be able to solve most of the queries you’ve posted. I’ve created all of your tables in my database so that I can make sure of that. I have a deadline to meet to pivot my career and so I am a little in rush mode and I’m so glad I found your videos when I did because they are exactly what I needed to supplement those courses. Again, I realize how much time and thought went into this and as the mascot I’d like to speak for all of your viewers and offer our appreciation for all of it 🙏🏻😀
Thank you Laura ☺️
You have the right attitude for learning SQL and I am sure you will solve every query in this blog..
All the best 👍
@@techTFQ thank you again for your encouragement and have a wonderful evening 🙏😀
You too Laura ☺️
14:35 you don't need to set condation d1.idd2.id
So far, the best video I have found on complex SQL. Great examples of practical value, very well explained. Thanks a lot.
I failed a DA interview because I was not able to solve a question similar to Query 9. But Now I am smarter than before because of you. Thanks a lot. Really very useful content
I am glad you found the video helpful bro
Every other SQL tutorial youtuber just shares the basics which is good , but going through these examples and approach is really well thought of.. Appreciate the work! Thank you
Thank you Musheer 🙏🏼
Glad you liked my work
After going through multiple videos. finally landed in the best channel. I am able to follow you effortlessly for more hours. Thank you so much.
Thank you!!! I discovered Process Query Language (PQL) that uses Lead & Lag times (different structure) and the concepts really help with understanding.
Your welcome Barry🙏🏼
Glad this helped ..
Nothing like your contents on this whole TH-cam. Genuinely appreciate your efforts in churning out such beneficial n functional contents🙏Also, the blog is just amazing. Clean, clear, authentic. Kudos to your efforts n intention👏🙌
Thank you very much ❤️
And there is nothing like your support 😍🙏🏼
FYI - I'm doing the exercises using MySQL (using POPSQL) and for query 5, using the line
INSERT INTO login_details values(113, 'James', current_date+6);
was giving me an error because it was trying to store 2021-11-32, so I had to change the line to
INSERT INTO login_details values(113, 'James', DATE_ADD(current_date, INTERVAL 6 DAY));
Great series of vidz, I'm learning so much and my head is starting to get into the SQL groove.
Thank you Gazbert for sharing the solution.
This is right.
And I so glad you are liking the content :)
This is by far the best video for understanding SQL queries, the way you have explained by running small parts first and than solving to get the end output and also the pace was very much decent. Thanks man ! and please continue to make more of such videos :)
Thank you Swati 🙏🏼
Truly appreciate such detailed feedback 🙂
So glad this helped you.
It is not. It is really not!
Was glad to see your "Download script"...at least for the 1st example also worked with SQLite. It also needed the rowid change for the SELECT. SQLite is stand alone and doesn't require a server.
Thank you Bill 🙏🏼
Glad to know you found this useful ☺️
superb, had been looking for someone for very long who teaches complex queries in simplest manner, finally search ends here.
Thank you Vijay 🙏🏼
Glad You liked my videos ☺️
select * from(
select *,max(salary) over (partition by dept_name ) as max_salary,
min(salary) over (partition by dept_name ) as min_salary
from employee)x
where salary in (x.max_salary,x.min_salary) - I tried this approach for Q3
Watched tons of SQL contents, this is by far best and quality content. Keep adding more. Please also share the SQL for entry level data analyst
Thank you Sagar 🙏🏼
Glad you liked it..
Sure SQL for data analysis, let me plan something
@@techTFQ do you have course on it ?
Hi Carlos, do not have any course as of now . May be will plan to create one in future..
Absolutely stunning and insightful video, I come here every 15 days to revise my SQL concepts.
OMG, this was my reaction when you cleared my doubt on lead and lag... I don't know whether you're a good employee or not but YOU'RE AN AMAZING TEACHER. I regret not taking your intermediate live sessions. Do tell me if you're starting a next batch on intermediate queries.
I am glad this video helped Ritika ..
as for next batch , have not planned it
@@techTFQ Hi, from where I can get files and I can use them as database?
So I can perform queries
This is by far the best tutorial for SQL-queries. You save my studies and my peace of mind
Thank you Amy. glad you liked it :)
Hi TFQ,
For Query 5 : From the login_details table, fetch the users who logged in consecutively 3 or more times.
Instead of lead function we can use Rank as well ryt. This also gives correct output.
Below is my Query and please let me know if this is the right way to use Rank function or not.
select distinct user_name from (select *,rank() over(partition by user_name order by login_date ) as rnk
from login_details ) where rnk >=3
;
it will work only for this type of data but if it was different then i don't think this will work
no its not working
Hey Mate ,
Because of you now I am fully confident about my problem solving abilities in SQL .
Thanks a lot for these Complex SQL Queries ❤️❤️
as a mac user, your videos were mashallah very helpful, especially the way you think gives a practical approach to finding solutions. As a beginner i find it very nice thanks brother and keep up good work.
Thank you Abin 🙏🏼
Glad the video helped ..
Thanks mitra khup chan shikavtoy ,mala tuza blog madhun khup kahi shikayla milale ,dhnaywad..!!
select emp_id,emp_name,dept_name,salary
from
(
select *,
min(salary) over (partition by dept_name) as min_salary,
max(salary) over (partition by dept_name) as max_salary
from employee
) as x
where
salary =x.min_salary or salary =x.max_salary
1M views… Masha Allaah… You deserve much more.. Keep growing n benefiting 👍👍👍
I think in the 4th exercise (query a) there is no need to put the a.ID b.ID because the condition d1.speciality d2.speciality automatically restrict that record from coming
Totally agree with many of the viewers comments. You are the best SQL guru I have seen on TH-cam. Wish you were our teacher in college when we learned these without this much clarity.Hats off to dedication and hard work..👏👌
That’s a very kind appreciation 🙂
Thank you Sudeep 🙏🏼
Am glad I can add some value through these video’s
This is the best advanced SQL video I have ever seen. Thank you very much!
Wow, thanks!
Thank you Thoufiq, I learned a lot from the examples you've provided. Greetings from Brazil 👋
So glad to receive feedback from Brazil 😃
I am so glad you liked it Torres 🙏🏼
Thanks a lot, have not touch SQL around 3-4 years after school, a new task requires me to start from fresh. Spending 5 hours on one query joining 5 tables is REALLY not fun and frustrated :(
Your welcome and I hope my videos can help you grasp SQL faster
Loved your step-by-step approach towards solving complex SQL queries. Hope to see more similar videos in the coming days and really appreciate your hard work in making such a helpful content.
Thank you Pranab for your kind words..
Glad the video helped ☺️
Cf
Īi
@@techTFQ III III i
Īi in i
Hi there, thank you so much for sharing your knowledge. I am self learning, and your examples have helped me so much with the advanced concepts. Thank you!!!!!!
I subscribed to your channel while you were still explaining query #2
Your speed and way of explaining as well as the examples you picked are SPOT ON !
WE NEED MORE VIDEOS, QUERIES and EXAMPLES FROM YOU !!
PLEASE POST MORE VIDEOS... THANK YOU !!
Thank you so much bro..
I am glad you liked the content.
Sure will post more such videos
THANKS SIR THIS MADE MY WINDOWSFUNCTIONS CONCEPT MORE CLEAR
superb examples of complex query ! Appreciate yours knowledge and this contain , thank you
Your welcome Prashanth 🙏🏼
Glad you liked it …
Thank you so much for sharing such an extreme knowledge with us. Now I'm able to get some idea on the complex queries and practicsing as well. All your videos are very much helpful for me. Thanks a lot for taking so much effort and time to make these videos. Easy to understand and grasp the hidden concepts practically. Plz do share more on window functions queries used in real-time.
God Bless You.👍🤝
for the seventh question of temperature i used lag function
with temp as
(select id , city ,temperature ,day,
case when temperature
TechTFQ: super great job. This is high quality knowledge sharing.
Like you said knowing the different clauses and expressions doesn’t mean being able to apply them to concrete queries.
Keep these great tutorials coming please. If you could increase the degree of complexity with aggregate functions that’d be super appreciated.
Can’t wait to watch your next vids. Got yourself a new subscriber.
Thanks a lot.
Thank you Mathieu 🙏🏼
So glad to read this comment..
will consider your suggestion to include more complexity in the future..
glad you are subscribed ☺️
The step by step explanation of each query helped develop good grasp over the concept . Thankyou very much for the precise explanation
Your welcome bro :)
Glad this helped
Your teaching methodology is superb.... I have shared it with my husband who is looking for a course in SQL. He too found it very useful, easy to understand.
Thank you so much 🙏🏼
Glad you liked it
Thank you for explaining.
One doubt
What if you have not specified d1.id d2.id in Self join question (Doctor and hospital one)
Fantastic..This helps infrastructure oriented DB engineers like us to quick assist customers with query tuning or performance tasks. Thanks for making time to share this dude.
Your welcome Lokesh 🙏🏼
Glad this helped
good instructions, I'm tired of learning hello world and this is perfect. not too complex and works with real world data
Glad it was helpful!
Thank you for this video. It's detailed and well explained. Hope to see more! I used Postgre to run the queries and it was successful, but when I tried the query for duplicate records on MSSQL, it returned an error saying (the ORDER BY clause is invalid in views...) Kindly suggest what to do.
Thank you for liking the content 🙏🏼
These queries were written in PostgreSQL but I will soon update my blog to have corresponding queries in MySQL and Microsoft SQL server also .. may be in couple of weeks
Thank you for the response. I look forward to seeing the video.
Thanks a lot man. One lesson teaches us subquery, ranking and distinct. All in one.
Nice examples..
I feel writing below query for finding duplicate records is bit easier .
Select user_id,user_name,email from
(Select user_name,count(user_name) un from users group by user_name) asd
Where asd.un>1
Thank you 🙏🏼
We can always a solve a query in several different ways and that’s the beauty of sql
You could use HAVING count >1 instead the WHERE clause. HAVING clause always works with GROUB BY.
@techTFQ the temperature question is crazy! Covered lead,lag so beautifully.
This channel is very good for learning SQL, the way of explaining and displaying content is superb. If this channel could give us videos on interview questions of top companies then we won't be needing to go to other websites.
Hi Ashish ,
Thank you for such kind words 🙏🏼
It’s so nice to see you have liked my work and it is beneficial to you 🙂
As for interview questions, I will plan it out in the near future..
Question 6 )
select *,
case when id % 2 = 0 and id < (lead(id) over(order by id)) then lag(student_name) over(order by id)
when id % 2 0 and id < (lead(id) over(order by id)) then lead(student_name) over(order by id)
else student_name
end from students;
Man, this tutorial is really awesome!!! Thank you so much for your detailed explanation. It will be very great if you post more videos on solving complex queries!!!
Thank you Siva 🙏🏼
Glad you liked it .. yes will be making more videos on solving sql queries
In q 4 you should take city in query too like d1.city= d2.city because same hospital can be in different cities if data is big.
This is an awesome tutorial video. It touches upon exactly the pain points and explains the concept in a great detail.
Thank you Broto 🙏🏼
Glad you found this helpful ☺️
Thank you this was powerful application of SQL, partitions, lags, leads and rnks, a lot to take in and learn
TFQ, I predict greatness for your channel with content like this. Seriously, you stand apart because your explanations are so clear and you put so much time and effort forward for your videos and this shows. I think I speak for all your subscribers when I say thank you, thank you. We SO appreciate all of your hard work. 100K will be in your rear view mirror before too long, my friend. 👍🏻😊
I also want to add that I’m so happy right now because I was having troubles with a Leetcode query I was trying to solve and after your terrific explanation about self-joins, which I’d struggled a bit with in the past, I was able to go right back there and quickly solve it. I don’t know if you’re interested in teaching, but you’re a natural at it. Thank you so much! I now understand something in a few minutes that had really confused me in the past! Blessings to you and yours for a wonderful November, TFQ!
Thank you thank you Laura 🙏🏼 🙏🏼
It’s so true that each of these videos take a lot of effort to make but getting this kind of feedback makes everything worth it..
I am short of words to thank you for your support and I just wish you success in everything you do..
I am also so glad to hear that you could apply the teachings in this video to solve leetcode queries..
I feel overwhelmed by this feedback ..
Thank you once again and have a great start to the month.. 🙏🏼☺️
@@techTFQ I used to have an art blog and it took quite a bit of effort, so I can only imagine the time to film, plan etc., but your explanations simplify complex operations so well that I feel your efforts are bound to bear fruit. Look how much your channel has grown already! You’re doing great, and we thank you again. 🙏🏻👍🏻
Thank you Laura 🙏🏼☺️
@@techTFQ I’m a new subscriber and you’ve gained over 1,000 followers since I’ve joined you last week 😱 which imo is amazing, TFQ!
Liked before finishing it, useful videos
For question#1 used CTE what do you think about it?
with duplicaterecords as
(
select *, count(user_name) as namecount from users
group by user_name
having namecount>1
)
select user_id, user_name, email from duplicaterecords;
I don’t think above query works ..
Very Complex inner join,left outer join, right outer join, with more than 3 tables,..plz post this as well
Just few hours ago I posted video about JOINS. In that I have written a query at the end where I joins multiple table using different type of joins. Do check that video out. link below:
th-cam.com/video/0OQJDd3QqQM/w-d-xo.html
I have learnt alot from this video, I thoungh I new not until iv watched video that has proven to me something
you literally make the best videos!! please keep making more with more queries and performance tuning tricks and interview focused complex queries. Thank you so much for your amazing content!
Thank you Muskan 🙏🏼
So happy to read this feedback ☺️
And yes I will make more query videos
24:58
with cte as (select *,
case when temperature
Hi I really enjoyed this video. I was wondering, is it possible to also use the row_number windows function to solve the third example on login frequency?
Hi Solomon,
Yes you can write a query using row_number window function to solve this as well.
In fact, I have posted a video on my channel giving a generic query using row number window function to fetch any no of consecutive records from a table. You can watch that video from the link below:
th-cam.com/video/8p_OzqIJ_p4/w-d-xo.html
you explained everything in a very good way, i never seen such a wonderful teacher on youtube. Thanks for helping us.
Bharat can u please explain difference between sql and sql scripting
Fantastic tutorial, very well explained step by step. All is clear to me after watching your vids. Thank you my friend!
Thank you so much bro 🙏🏼
Very glad to know you liked the content 🙂
ة
Cristal clear. Pure quality. Thanks!
Your welcome 🙏🏼
Glad you liked it
Realy very good content delivered. I never seen anyone who explain like this. Great work. ❤️
Thank you Hari 🙏🏼
So glad to hear such positive feedback.. glad this helped 🙂
The best material for SQL in TH-cam that I have sawn, amazing blog as well, please go on such queries, which will really help many learners including myself.
Thank you Basavaraj 🙏🏼
Glad you liked it 🙂
I used this approach for problem 1.
select user_name, count(user_name) as duplicate_number
from users
group by user_name
having duplicate_number>1
These are sooooo helpful. You're doing God's work!! 😁
Thank you Maxim for such kind words man 🙏🏼
So glad I a am able to add some value through these videos ..
Clearly understanding the way u justify each and every attributes....thank you
Best channel for SQL
Very well explained
Appreciate your hard work !!!!
Expecting similar videos to become Master in SQL
Thank you very much 😊
Thanks a lot for these kind words 🙏🏼🙏🏼
I am so happy these videos are helping so many people ☺️☺️
a very admiring content provided in your lecture ....and explanation is very glamourous
Sir, could you please make a video on indexes and views and interview questions based on that also.. It would be really helpful and all your videos are great.. Keep rocking❤️
Thank you so much for your kind words 🙏🏼
So glad you liked my videos .
Surely will consider your suggestions, let me see when I can cover these topics too..
Thank you so much, that is something and this is the first time where i enjoyed learning. Thank you sir
Glad to hear that Vijay
Excellent. Quick question on the temperature query, would an alternative query using self join be more concise? Rather than nested case statement. Keep up the great work.
Thanks Ed for liking the content 🙏🏼
You can always write a query on many different ways and using self join may be an option for this kind of query but if you wish to fetch any no of consecutive records then I have made another video covering it.
I’ll leave a link to it below.. have a look at this generic solution as well.
th-cam.com/video/8p_OzqIJ_p4/w-d-xo.html
Sir, Literally u r a gem of a person. Thank u so much.
Thank you buddy
your doing hell lot of work (day and night ),have some rest dude, by the way awesome lesson
Thanks a lot Lalit :)
I am really grateful that i found your channel and it is helping me a lot. Thank you
Very well explained video for learners like me who face problems with complex queries. Request you to provide more new queries and some source where I can practice to brush my basic SQL queries as well.
Thank you Priyanka :)
Glad this helped..
As for sources, i'll make a video when I come across a good resource for practicing SQL queries..
Thank you Thoufiq for this video, I’m anted to find out if writing the query for the records users who logged in 3 or more times shouldn’t have been
Select distinct(user_name)
From (
Select *,
Case when user_name = lead(user_name, 3) over(order by login_id)
Then username
Else null
End as repeated_users
From login_details) x
Where x.repeated_users is not null;
Your explanations are kind of addictive :)
Can’t stop or skip in between ,
The use cases are very well descriptive , Hats off to your amazing effort !
Finally managed to stop at 12:10 am Central European Time ;)
Haha thank you bro ☺️
Glad you liked it
simple and effective with easy flow narration.
Thank you 🙏🏼
5th query I have done using group by, Once check it
select USER_NAME as repeated_names
from login_details
group by user_name
having count(*)>3
I found this is the best tutorial on youtube tq sir and i request you to add more queries for practice
Thank you so much 🙏🏼
Very happy to know you liked it..
Sure will make more such videos
my answer for the weather query ms sql
select id,city,temperature,day from
(select *,
case when temperature
find your tutorial very clean n easy to catch
Glad you think so Ataullah
Thank you so much Sir. Please continue these complex queries as a series .
Thank you Ramireddy 🙏🏼
Yeah will do more such videos..
Yesterday I posted another video covering 20 sql queries.. do check it out
Most difficult thing in SQL is the point where something is null. In other languages where the approach is more structural, in SQL this null value can blow up your query to become a Stephen King book.
You can handle NULL values pretty easily in SQL as well..
Perhaps some more practice and you would realize it..
Thanks for this video. It was indeed a good practice for me.
Just thought, for the consecutive login problem, i tried a different way may be this is a traditional way of writing the query assuming the login_id definition as identity(100,1) column
select distinct l1.user_name
from login l1 join login l2
on l1.user_name = l2.username and l2.login_id = l1.login_id +1
join login l3
on l2.user_name = l3.user_name and l3.login_id = l2.login_id+1