Solving SQL Interview Queries | Tricky SQL Interview Queries
Vložit
- čas přidán 10. 09. 2024
- In this video, I will explain and solve 3 tricky SQL Interview Queries. These are the SQL Queries which can be expected during SQL Interviews for both beginners and experience level interviews.
Many times, SQL Queries given during SQL Interviews are more tricky than complex. The solution to the SQL question may be simple but understanding the question and dataset and analyzing the data will play the most important role when solving such SQL queries. Hence mentioning the tricky SQL queries which you may expect during SQL interviews.
My email id: techtfq@gmail.com
All the Dataset, SQL scripts and queries written in this video can be found in my blog.
Link to my blog: techtfq.com/bl...
My recommended platform to practice SQL queries: www.stratascra...
My recommended platform for SQL Course: learnsql.com/?...
Consider SUBSCRIBING to my channel if you wish to learn SQL, Python and Data Analytics concepts.
🔴 WATCH MORE VIDEOS HERE 👇
✅ SQL Tutorial - Basic concepts:
• SQL Tutorial - Basic c...
✅ SQL Tutorial - Intermediate concepts:
• SQL Tutorial - Interme...
✅ SQL Tutorial - Advance concepts:
• SQL Tutorial - Advance...
✅ Practice Solving Basic SQL Queries:
• Practice Solving BASIC...
✅ Practice Solving Intermediate SQL Queries:
• Practice Solving INTER...
✅ Practice Solving Complex SQL Queries:
• Practice Solving COMPL...
✅ Data Analytics Career guidance:
• Data Analytics career ...
✅ SQL Course, SQL Training Platform Recommendations:
• SQL Course / Training
✅ Python Tutorial:
• Python Tutorial
THANK YOU,
Thoufiq
For the second one in oracle this query also does the trick in one single query
SELECT NVL(A.ID,B.ID) AS ID,
CASE WHEN B.NAME IS NULL THEN 'New in Source'
WHEN A.NAME IS NULL THEN 'New in Target'
ELSE 'Mismatch'
END as Comment1
FROM source A
FULL JOIN target B ON A.ID = B.ID
WHERE NVL(A.NAME,'$') NVL(B.NAME,'$');
I used full join and excluded the names that matched then is just added the Case.
Great Video!
I am really thankful to you .. few months ago I was not so confident on myself to give interviews.. after started learning from your videos given around 4-5 interviews confidently. Thank you😊..
Miss likshma how to apply interview
Plz tellme
I wanna ask too
அருமையான எஸ் பி எல் வினாவல் அருமையான எஸ் பி எல் லாங்குவேஜ் சொல்லி கொடுத்ததற்கு நன்றி
The way you explained and the pain you have taken to make such wonderful videos is way beyond saying thanks...you are a rockstar man....keep posting such kind of tricky queries...will help someone get a job...all the best bro...
Thanks a lot bro
He is a savior. I am lucky that I came across his videos. Such a lucid explanation. Thank You. Please upload more of SQL Queries needed for Data Science Folks !!
Glad you liked my contents :) thank you
@@techTFQ My Pleasure, its for my benefit
Please add this video to the SQL playlist! Started watching the joins video and I have never seen a better explanation before. Love the content!
That last example was lit! I was having difficulty understanding recursive CTEs before, but now I clearly get it.
Sir, can you explain about what exactly a sql/ plsql developer do in software industry and what are the career growth options in future for sql developers in IT industry. Is it better to go through in that domain?
Logic is correct... In second query you have used union operators and same table is scanned 3 times which may not be suitable for big tables... We can use cte for the same
I just got to know He is from Malesiya , such really amazing contents not finding anywhere in youtube , please keep posting more videos like this 🙏🏻🙏🏻, really feeling like big brother is helping to understand such complex things in a simpler way 😇, Love from India 🥰
You are really explaining the complex queries which will be very helpful for professionals as well
Glad you liked it
I wouldn't ever hire the one who solves the second task like you did.
This is the clear task for the FULL JOIN
You are simply amazing, Thoufiq! I took your SQL Bootcamp last year and often come back to your content for additional practice and learning. Stay blessed!
The best channel to learn sql topics as well as solve questions.
hi taufiq, the approach for 3rd problem was out of the world. thanks for such a mind-blowing approach.
Thank you Sumit :)
Thanks a lot TFQ. Your videos is not just a video it is a service for many techs like me. Beautiful explanation that too for tricky questions. More than that the SQL commands to execute and practice in our IDE's that you share get me more to my fullest satisfaction. A special thanks for that too buddy.
Please keep up the good work.
I could come up with this -
select comment from (select * from comments_and_translations
where translation is null) x
union
select translation from (select * from comments_and_translations
where translation is not null) x
Nice question and answers
However the third question can be solved without rownumber()
as the < can be directly applied on team code
Hi, Your videos are very unique and easy to learn
Can you please make videos related to Grouping sets, Rollup, Within group.
And also please make related to dynamic sql
Thanks for your time.
Thank you bro and noted on the request
Thank you sir, for making such informative videos. it's really helping me practice for my upcoming interviews. One request is to please make videos on puzzles and guesstimates for full practice for the role of data analyst.
Thanks TFQ the last question was everything, I was blocked on how to remove mirror effect records from my query.
Hey Taufiq, Could you please make a video on indexing .You explain very well. Want to understand SQL indexing thoroughly but couldn't find any video on your channel. If you already have made video on it, could you please share the link here?
Great explanation. Looks like for the third query you had already solved the second part first using not equal on team names.
I did but I wanted to provide a more meaningful and easier to understand solution at the end hence used row number concept
Thanks a lot TFQ for giving such wonderful explanation for all these questions.
I started watching your YT channel a month back your teaching style and your logical explanation for each concepts MINDBLOWING.
Thank you again for sharing your knowledge.
Thank you for the kind words bro 🙏🏼🙏🏼
Kindly come up with real life Day to day activity a SQL Developer or a data analyst does in the industry or the company. Like please explain when we join any company how are these Query useful there with some kind of live examples. For instance how a data analyst uses SQL in his day to day work at the office. Also please continue providing such videos and please come up with full tutorial videos in a sincere format like a course
Noted on the request bro, let me think about it
Hi, i have attended interview recently and they asked question about which command is used to find error? Could you please help this? Thanks in advance.
Write any wrong query and u will get the error!
@@unawarenoob2968 😂
@unawarenoob 🙏🏻🙏🏻🙏🏻🤣🤣🤣
Where r u now? Placed? If yes... where
Begin catch
For question 1 I would use
Select isnull(translation, comment) from table
Me too, much easier…
@@jameses4413 yes
is it isnull or ifnull
@@atwineian375 isnull .it will return the non null value.
your videos helps me a lot to solve complex queries...
I am glad to hear that buddy
Really you are born to teach .just loved your way of explaining Thank you so much
Words are not enough to say thank you , love this bro , GBU
Glad you liked it buddy :)
Hi sir, we can write it like this select id , case when id=3 then "New in source"
When id =4 then "New in target"
When id =5 then "mismatch"
End as comment
From source
Full outer join target
Where source.nametarget.name
Yes right.. I have provided solution using full outer join in my blog
it was amazing learning. Please make something on normalization if possible
Thank you and will consider your request
It will be very helpful
God bless you. Taking your precious time and helping others.
query 2: without joins
select id , case when id = 3 then 'new in source' else 'mismatch' end as output from source where id in(3,4)
union
select id ,'new in target' as output from target where id in (5) OR
select id , decode (id ,3,'new in source',4,'mismatch') as output from source where id in(3,4)
union
select id ,'new in target' as output from target where id in (5);
great your way of explaining problem and solving them adds fun for them also who thinks sql very tough .great job sir.
case- when -then- else ....like if ,elif, else condition (python )
Your exemples with the excel really helped understand the logics, thanks!
Glad you liked it
Thanks for your videos, very helpful for me when I started to find a job. Thanks a lot
good explanation with all examples. Thank you
Nice one I feel very relax to solve them
Thanku very much
the way you explained is next level Sir Thank You so much
there's many way to do the second query.. it's pretty easy.. the third one now that is challenging!
very very helpfull, thank you. will be usefull if more such videos are brought out
Thank you so much for the thoughtful explanation. 😊
One thing came into mind, 2nd query with union of 3, instead, can we use full join with case statement to print the desire output?
He said yes - see his blog
you are best educator ever for sql 🙏
really, very appreciative video and the channel itself fro learning sql.
Thanks a lot sir for providing this.
Thanks you Wagh :)
Very smart query. Thanks for sharing this query
Your welcome buddy
Hi sir, pls do video on sql in advanced level
Noted bro
After the 3rd Query , me "DAMN" !!
Thank you this was powerful and expanded my understanding on the application of SQL
dear ftq salute on your explanation on sql subject
Thank you buddy
make more videos on complex query or sql query that we gonna write when we get hire in companies
Sure will do
Amazing explanation, these 37 minutes were totally productive
you have excellent way of explaining the query and how system works.. really great videos.. good work
Sir, Could you please make a video on Index in SQL? How it will be useful in real time?
Sure will do
Thanks. Thanks a lot. Your concepts are easily understandable.
Glad to hear that bro
The video is quite informative, and way of teaching is great.
Really good explanation.. easy to understand even the problem is very complex.. thank you so much for your time
Guyz watch everyday Data science channel where he already solved so many leetcode interview questions.. Probable qsn for interview.. Do watch tfq.. Of you stuck somewhere get help there.
Thank you Rakesh :)
Alternate solution for problem 2 in postgres--
It's essentially 3 steps:
1 Use a FULL OUTER JOIN on id to combine all the records
2. Use WHERE to pick out the rows where a) Source has a null id, b) Target has a null id, or c) Source name differs from Target name.
3. Use two CASE statements in SELECT to pick out the non null data and hard code in our comments.
The conditions can directly be used in the case statement I think.
Then Order By DESC COMMENTS
Excellent! Thank you very much. Such a hard concept to understand, you made so easy sir.
How to split a string into 2 strings and make first and second as capital letter. Example goodmorning(no space) -Good Morning
Very nice, Please make videos on Stored procedure and User defined functions wrt its usage in job.🙏
Thank you and sure will do
This guys explanation is perfect and amazing
Just loved the way you teach....thanks a ton brother....Respect from INDIA.
I just got to know He is from Malesiya , such really amazing contents not finding anywhere in youtube.
hello all , here is my query with easy understanding for the last IPL match query . For each team play with every other team twice , here we can use cross join ... select IPL.team_name , O.team_name from IPL ,IPL as O
Where IPL . teamcode O. teamcode
I never imagined that i can also write a query with understanding SQL thank you techTFQ
excellent work sir !! please come with more practical example like this ,,
Thank you Das and will do
I got some tricky SQL queries with answers,
I hope it will help me
Thank you for taking your time to explain this.
Glad you liked
Just Awesome Brother ! SQL is an ocean and you're helping others to voyage !!
Thank you buddy
Hello, You are doing a great job with a good explanation. please make a detailed video on Database Performance Tuning
Thank you Sulaiman and sure will do
The 3rd question is very good.
sir plz make the video sql procedure and trigger
Sure will do
Hi ,
Please make a Vedio on Normalisation and Indexing , everywhere they ask these concepts
noted, will plan it
Sir could please prepare SQL questions on consecutive days or consecutive numbers related way questions give a thought process how to solve those SQL questions
Thank tou for serving us the knowledge we need!
thanks teacher, im learning alot your a great teacher
Excellent explanation...thank u so much for such kind of sessions.
Most welcome bro!
Very useful .
I was under impression to join table only = can be used , you shown less than symbol also works .
First time seen use of coalesce function . Can you list down such rarely used but imp. Functions and what are names in different RDBM , is same available in MySQL ?
I really Appreciate your efforts and excellent work. looking forward to more such videos.
Thank you bro , glad this helped ..
And noted on the request, will consider it
thank you so much. superb video
Glad you liked it
Thank you for sharing another great video..
Please make video on data import, export and back-up.
Thanks for your time..
Thank you Abhishek and sure will do :)
Super SQL skills
Thank you 🙏🏼
Awesome Explanation on Third Query... Thank You so much.
Sahi video, sahi samay par!
Hope this helps 👍
Make a separate video on self join & it's usage
I have already made it. Please check my JOINS tutorial video
Ur way of explanation is super,
Keep go like this sir
How do you solve Query no:2 using a subquery, would like to see how a subquery is different to that Union query
Hi, these kind of videos really helps, and the way you teach is very good. You are helping us in a great way possible. Keep up the good work.
with cte as
(
select coalesce(a.id,b.id) as id,
case
when a.id=b.id and a.name=b.name then 'Matched'
when a.id is not null
and b.id is null
and a.name is not null
and b.name is null then 'New in source'
when a.id is null
and b.id is not null
and a.name is null
and b.name is not null then 'New in Target'
else 'Missmatch' end as outut
from source a
full join target b on
a.id=b.id
)
select * from cte where outut'matched'
This is really wonderful video. Thank you so much. Please do come up with such wonderful contents.
Thank you bro
please make more videos on SQL problems
sure will do
with cte as (
select s.id as source_id, s.name as source_name,
t.id as target_id , t.name as target_name
from source s full outer join target t on
s.id = t.id),
cte1 as (
select source_id, target_id,
case when target_id is null then 'New in Source'
when source_id is null then 'New in Target'
when (source_id = target_id and source_name != target_name) then 'Mismatch'
end as comment
from cte)
select coalesce(source_id, target_id), comment from cte1 where comment is not null;
>> for second question
thats right. I have provided solution using FULL OUTER JOIN already in my blog
sorry thanking you ,first thig Happy Holli sir,sorry sir i miised your four classed due to payment failure,weekly make two tricky questons sir
Happy Holi bro..
Sorry for that and yes will try making more such videos
Nice keep posting such videos .
Please share video about complex topic in sql
Thank you Saurav and will do
Very Well Explained.
This video was really interesting. Your explanations are great! Thank you
Hi ,
Can you please suggest any to learn from? I have started learning SQL.
Thanks!
ahhh..saying this from past 10 videos, please make a video on store procedure.
Sorry bro , will do it within the next 2-3 weeks
very helpful all the sql queries examples thanks brother please share more the complex sql queries real life examples
Just trying to understand in second example you have used three joins instead of that can’t we use full outer join and compare source and target using case to get comment value?
Yes you can solve it using full join too ..
Just that not every rdbms supports full join so I used this solution but I’ll add solution using full join too in my blog..
Thanks for suggesting