Solving SQL Interview Queries | Tricky SQL Interview Queries

Sdílet
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

Komentáře • 473

  • @ManuelrPM24
    @ManuelrPM24 Před rokem +12

    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!

  • @lakshmipriya8416
    @lakshmipriya8416 Před rokem +27

    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😊..

  • @vlog.444
    @vlog.444 Před 5 měsíci +3

    அருமையான எஸ் பி எல் வினாவல் அருமையான எஸ் பி எல் லாங்குவேஜ் சொல்லி கொடுத்ததற்கு நன்றி

  • @madhusudhanreddyt2838
    @madhusudhanreddyt2838 Před 2 lety +15

    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...

  • @HotThupka
    @HotThupka Před 2 lety +7

    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 !!

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Glad you liked my contents :) thank you

    • @HotThupka
      @HotThupka Před 2 lety +1

      @@techTFQ My Pleasure, its for my benefit

  • @darshpancholi4919
    @darshpancholi4919 Před 2 lety +17

    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!

  • @rhys4473
    @rhys4473 Před měsícem +1

    That last example was lit! I was having difficulty understanding recursive CTEs before, but now I clearly get it.

  • @klokeswarreddy3205
    @klokeswarreddy3205 Před 2 lety +18

    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?

  • @siddheshaddarkar4074
    @siddheshaddarkar4074 Před 4 měsíci +1

    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

  • @bedaprakash9609
    @bedaprakash9609 Před rokem +1

    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 🥰

  • @akhilreddy5208
    @akhilreddy5208 Před 2 lety +4

    You are really explaining the complex queries which will be very helpful for professionals as well

  • @westgot2
    @westgot2 Před rokem +1

    I wouldn't ever hire the one who solves the second task like you did.
    This is the clear task for the FULL JOIN

  • @Hsalz
    @Hsalz Před 6 měsíci +1

    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!

  • @harsohrabsingh8020
    @harsohrabsingh8020 Před rokem +2

    The best channel to learn sql topics as well as solve questions.

  • @sumitbarde3677
    @sumitbarde3677 Před 2 lety +2

    hi taufiq, the approach for 3rd problem was out of the world. thanks for such a mind-blowing approach.

  • @karthikvenkataram4790
    @karthikvenkataram4790 Před rokem +8

    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.

  • @srushtiOm
    @srushtiOm Před 3 měsíci +1

    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

  • @venkateswararaodevisetti8684

    Nice question and answers
    However the third question can be solved without rownumber()
    as the < can be directly applied on team code

  • @ganeshv791
    @ganeshv791 Před 2 lety +18

    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.

    • @techTFQ
      @techTFQ  Před 2 lety +6

      Thank you bro and noted on the request

  • @VibeQueen24
    @VibeQueen24 Před 3 měsíci +1

    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.

  • @cococnk388
    @cococnk388 Před 11 měsíci +1

    Thanks TFQ the last question was everything, I was blocked on how to remove mirror effect records from my query.

  • @archana-sv1hh
    @archana-sv1hh Před 7 měsíci +1

    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?

  • @tarunsaha439
    @tarunsaha439 Před 2 lety +3

    Great explanation. Looks like for the third query you had already solved the second part first using not equal on team names.

    • @techTFQ
      @techTFQ  Před 2 lety +1

      I did but I wanted to provide a more meaningful and easier to understand solution at the end hence used row number concept

  • @shivashankargopal1678
    @shivashankargopal1678 Před 2 lety +3

    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.

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Thank you for the kind words bro 🙏🏼🙏🏼

  • @ashutoshkumar-gv7wu
    @ashutoshkumar-gv7wu Před 2 lety +2

    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

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Noted on the request bro, let me think about it

  • @shailajakesani8048
    @shailajakesani8048 Před 2 lety +30

    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.

  • @Kabboch
    @Kabboch Před 2 lety +3

    For question 1 I would use
    Select isnull(translation, comment) from table

  • @deepaksoni2667
    @deepaksoni2667 Před 2 lety +2

    your videos helps me a lot to solve complex queries...

    • @techTFQ
      @techTFQ  Před 2 lety

      I am glad to hear that buddy

  • @debasismohanty1311
    @debasismohanty1311 Před 7 měsíci

    Really you are born to teach .just loved your way of explaining Thank you so much

  • @suryakantchavan4887
    @suryakantchavan4887 Před 2 lety +1

    Words are not enough to say thank you , love this bro , GBU

    • @techTFQ
      @techTFQ  Před 2 lety

      Glad you liked it buddy :)

  • @sparshmittal705
    @sparshmittal705 Před 2 lety +2

    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

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Yes right.. I have provided solution using full outer join in my blog

  • @amanadhikary8030
    @amanadhikary8030 Před 2 lety +5

    it was amazing learning. Please make something on normalization if possible

  • @2011var
    @2011var Před rokem

    God bless you. Taking your precious time and helping others.

  • @ektashah07
    @ektashah07 Před 11 měsíci +1

    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);

  • @ctnrandhawa7019
    @ctnrandhawa7019 Před rokem

    great your way of explaining problem and solving them adds fun for them also who thinks sql very tough .great job sir.

  • @ermanojku
    @ermanojku Před 14 dny

    case- when -then- else ....like if ,elif, else condition (python )

  • @odaya9946
    @odaya9946 Před 2 lety +1

    Your exemples with the excel really helped understand the logics, thanks!

  • @maidelfigueredo4596
    @maidelfigueredo4596 Před rokem

    Thanks for your videos, very helpful for me when I started to find a job. Thanks a lot

  • @NageshwariShankarappa
    @NageshwariShankarappa Před měsícem

    good explanation with all examples. Thank you

  • @zishan53
    @zishan53 Před 2 lety +1

    Nice one I feel very relax to solve them
    Thanku very much

  • @srinubathina7191
    @srinubathina7191 Před rokem

    the way you explained is next level Sir Thank You so much

  • @misterihorror1993
    @misterihorror1993 Před rokem

    there's many way to do the second query.. it's pretty easy.. the third one now that is challenging!

  • @SunithaRamalingam
    @SunithaRamalingam Před měsícem

    very very helpfull, thank you. will be usefull if more such videos are brought out

  • @amit.pawase007
    @amit.pawase007 Před 2 lety +2

    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?

  • @gyanprakashmishra9132

    you are best educator ever for sql 🙏

  • @waghdipak2358
    @waghdipak2358 Před 2 lety +1

    really, very appreciative video and the channel itself fro learning sql.
    Thanks a lot sir for providing this.

  • @sathishkumar-yd3pk
    @sathishkumar-yd3pk Před 2 lety +1

    Very smart query. Thanks for sharing this query

  • @ExploreRudrashree
    @ExploreRudrashree Před 2 lety +4

    Hi sir, pls do video on sql in advanced level

  • @vishnuprasathkv
    @vishnuprasathkv Před 2 lety +1

    After the 3rd Query , me "DAMN" !!

  • @infamismworldwild6248
    @infamismworldwild6248 Před 3 měsíci

    Thank you this was powerful and expanded my understanding on the application of SQL

  • @rameshchavda4117
    @rameshchavda4117 Před 2 lety +1

    dear ftq salute on your explanation on sql subject

  • @jaychopra8932
    @jaychopra8932 Před 2 lety +1

    make more videos on complex query or sql query that we gonna write when we get hire in companies

  • @Sunny-ok7dl
    @Sunny-ok7dl Před rokem

    Amazing explanation, these 37 minutes were totally productive

  • @ruheequreshi9741
    @ruheequreshi9741 Před rokem

    you have excellent way of explaining the query and how system works.. really great videos.. good work

  • @anandhvdm6957
    @anandhvdm6957 Před 2 lety +3

    Sir, Could you please make a video on Index in SQL? How it will be useful in real time?

  • @pratyakshaparashar5306
    @pratyakshaparashar5306 Před 2 lety +1

    Thanks. Thanks a lot. Your concepts are easily understandable.

    • @techTFQ
      @techTFQ  Před 2 lety

      Glad to hear that bro

  • @krishpoptani7862
    @krishpoptani7862 Před 2 měsíci

    The video is quite informative, and way of teaching is great.

  • @rajasekharareddyb668
    @rajasekharareddyb668 Před rokem

    Really good explanation.. easy to understand even the problem is very complex.. thank you so much for your time

  • @rakeshkumarrout2629
    @rakeshkumarrout2629 Před 2 lety +1

    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.

  • @yrrep27
    @yrrep27 Před 2 lety +12

    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.

    • @007SAMRATROY
      @007SAMRATROY Před rokem +1

      The conditions can directly be used in the case statement I think.

    • @PeachesO-NE
      @PeachesO-NE Před rokem

      Then Order By DESC COMMENTS

  • @jitendrashelar4123
    @jitendrashelar4123 Před rokem

    Excellent! Thank you very much. Such a hard concept to understand, you made so easy sir.

  • @user-lk7zt8cp2g
    @user-lk7zt8cp2g Před 2 lety +1

    How to split a string into 2 strings and make first and second as capital letter. Example goodmorning(no space) -Good Morning

  • @ratneshraj4653
    @ratneshraj4653 Před 2 lety +2

    Very nice, Please make videos on Stored procedure and User defined functions wrt its usage in job.🙏

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Thank you and sure will do

  • @XxLenasXx
    @XxLenasXx Před rokem

    This guys explanation is perfect and amazing

  • @shaikusman536
    @shaikusman536 Před rokem

    Just loved the way you teach....thanks a ton brother....Respect from INDIA.

    • @bedaprakash9609
      @bedaprakash9609 Před rokem

      I just got to know He is from Malesiya , such really amazing contents not finding anywhere in youtube.

  • @user-om7le1cs5i
    @user-om7le1cs5i Před rokem

    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

  • @nirmaldas4749
    @nirmaldas4749 Před 2 lety +2

    excellent work sir !! please come with more practical example like this ,,

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Thank you Das and will do

  • @Anbumanie3011
    @Anbumanie3011 Před 6 měsíci

    I got some tricky SQL queries with answers,
    I hope it will help me

  • @guzmanerpr
    @guzmanerpr Před 9 měsíci

    Thank you for taking your time to explain this.

  • @bharatk212
    @bharatk212 Před 2 lety +1

    Just Awesome Brother ! SQL is an ocean and you're helping others to voyage !!

  • @sulaimansheikh6050
    @sulaimansheikh6050 Před 2 lety +2

    Hello, You are doing a great job with a good explanation. please make a detailed video on Database Performance Tuning

    • @techTFQ
      @techTFQ  Před 2 lety

      Thank you Sulaiman and sure will do

  • @utubemovies1
    @utubemovies1 Před rokem

    The 3rd question is very good.

  • @AsadAli-wi1xs
    @AsadAli-wi1xs Před 2 lety +3

    sir plz make the video sql procedure and trigger

  • @NeverStopLearning56
    @NeverStopLearning56 Před 2 lety +1

    Hi ,
    Please make a Vedio on Normalisation and Indexing , everywhere they ask these concepts

  • @adinajoshisatyavardhan6543
    @adinajoshisatyavardhan6543 Před 3 měsíci

    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

  • @zacharyrohrback
    @zacharyrohrback Před 5 měsíci

    Thank tou for serving us the knowledge we need!

  • @traumegaz
    @traumegaz Před 11 měsíci

    thanks teacher, im learning alot your a great teacher

  • @satyabadiraut1191
    @satyabadiraut1191 Před 2 lety +1

    Excellent explanation...thank u so much for such kind of sessions.

  • @ashutoshbafna6617
    @ashutoshbafna6617 Před 2 lety +4

    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.

    • @techTFQ
      @techTFQ  Před 2 lety +2

      Thank you bro , glad this helped ..
      And noted on the request, will consider it

  • @murtazajabalpurwala8124
    @murtazajabalpurwala8124 Před 2 lety +1

    thank you so much. superb video

  • @abhishekgowda1776
    @abhishekgowda1776 Před 2 lety +1

    Thank you for sharing another great video..
    Please make video on data import, export and back-up.
    Thanks for your time..

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Thank you Abhishek and sure will do :)

  • @saradatalluri9577
    @saradatalluri9577 Před 2 lety +1

    Super SQL skills

  • @bmanikanndan
    @bmanikanndan Před 2 lety

    Awesome Explanation on Third Query... Thank You so much.

  • @ankitapriya13
    @ankitapriya13 Před 2 lety +1

    Sahi video, sahi samay par!

  • @prashantprabhat4223
    @prashantprabhat4223 Před 2 lety +1

    Make a separate video on self join & it's usage

    • @techTFQ
      @techTFQ  Před 2 lety

      I have already made it. Please check my JOINS tutorial video

  • @bhanuchandarpr1122
    @bhanuchandarpr1122 Před 2 lety

    Ur way of explanation is super,
    Keep go like this sir

  • @GracefulTalesPluto
    @GracefulTalesPluto Před 2 lety +1

    How do you solve Query no:2 using a subquery, would like to see how a subquery is different to that Union query

  • @anish_k
    @anish_k Před 2 lety

    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.

  • @aviparihar5792
    @aviparihar5792 Před rokem

    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'

  • @anirbansarkar6306
    @anirbansarkar6306 Před 2 lety +1

    This is really wonderful video. Thank you so much. Please do come up with such wonderful contents.

  • @shruthig8817
    @shruthig8817 Před 2 lety +1

    please make more videos on SQL problems

  • @karangupta_DE
    @karangupta_DE Před 2 lety +1

    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

    • @techTFQ
      @techTFQ  Před 2 lety

      thats right. I have provided solution using FULL OUTER JOIN already in my blog

  • @kancharalaparameshwarreddy3837

    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

    • @techTFQ
      @techTFQ  Před 2 lety

      Happy Holi bro..
      Sorry for that and yes will try making more such videos

  • @sauravrajchaudhary9036
    @sauravrajchaudhary9036 Před 2 lety +1

    Nice keep posting such videos .
    Please share video about complex topic in sql

    • @techTFQ
      @techTFQ  Před 2 lety

      Thank you Saurav and will do

  • @ayazahamed8254
    @ayazahamed8254 Před 2 měsíci

    Very Well Explained.

  • @benlong1062
    @benlong1062 Před 11 měsíci

    This video was really interesting. Your explanations are great! Thank you

  • @Rajeevkumar-ru3yv
    @Rajeevkumar-ru3yv Před 11 měsíci

    Hi ,
    Can you please suggest any to learn from? I have started learning SQL.
    Thanks!

  • @Buzzingfact
    @Buzzingfact Před 2 lety +1

    ahhh..saying this from past 10 videos, please make a video on store procedure.

    • @techTFQ
      @techTFQ  Před 2 lety +1

      Sorry bro , will do it within the next 2-3 weeks

  • @darshanwala5561
    @darshanwala5561 Před rokem

    very helpful all the sql queries examples thanks brother please share more the complex sql queries real life examples

  • @technicalmaster4066
    @technicalmaster4066 Před 2 lety +2

    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?

    • @techTFQ
      @techTFQ  Před 2 lety +1

      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