Top 10 SQL Interview Queries | Popular SQL Queries for SQL Interview

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video is sponsored by learns ql.com hey everyone in this video I'm going to share with you my top 10 SQL queries that in my opinion are very commonly asked during SQL interviews now if you are able to solve these 10 SQL queries and not just these 10 but if you are able to solve these type of SQL queries then you give yourself a very good chance to clear almost any SQL interview now before I can start I want to mention that I have 10 SQL queries I will not be able to solve all the 10 SQL queries in this video because then the video is going to to be extremely long rather I'll just be spending maybe 1 minute on each SQL query trying to quickly explain what the query is what the problem statement is and what my solution is okay now all the solution the scripts the data sets and the problem statement everything I'll be placing it in my blog I'll leave the link to my blog in the video description so you can definitely download it for free and then learn it yourself okay now if there are any SQL queries for which you need more details more explanation then let me know in the comments below and I'll try to make a separate video about it in the the future okay now let's start with the query number one so the first query is how do you delete duplicate data in your table and I think this is a very common question that you can always expect in your SQL interviews so I have been given a table it's a cars table it has information about different cars so I have model ID model name the color of the car and the brand of the car and I can see that I have seven records here but the first two records it belongs to the car Nissan Leaf you can see that these two records are actually duplicated even though the ID is different but these details are of the same car right same way if I go down you can see that I have Hyundai ionic 5 and these two records the record number five and six are also duplicated right now I need to write a query which is going to delete these duplicate records okay and output should look something like this so this is my requirement now in order to solve this problem what I can do is I can basically delete duplicate data in multiple different ways in fact I have made a separate video where I've shown you 10 different different queries to delete duplicate data okay but I'm not going to be explaining all of that in detail now I'll be leaving a link to that particular video in the video description so if you want to check out and understand how to write all of these queries I you can probably watch that video okay now for this particular query here whenever I ask this question to a candidate whenever I'm taking an interview I always ask them to provide me multiple Solutions and that is why I'm going to give you three different solutions to this particular problem here okay so you can see that I have this cars data here and if I just run this you can see that I have all of that data here the same data that I showed you now one the solution number one that I have to delete duplicate data is by using the group by command and by taking the minimum of the unique identifier okay so here I have a unique identifier model ID what I'll do is I'll group the data based on the model name and the color so wherever I have duplicate data I will kind of get multiple records for that right from that multiple records I'll take the minimum of the model ID so in this case for every record I will get only so when I run this query right so if I show you so I have seven records here if I run this I'll only get five because these are the unique five records in that table okay so what I'll do is I'll delete all the records from the car which are which are basically anything other than these five okay so this is my method number one this will delete the two records so when I run it you can see that it deleted two records okay so this is my solution number one now similarly I have solution number two where I'm kind of using the similar method I'm using the group by but this time you can see here I used a not in I was deleting all the records other than these unique records but here what I do is I write a subquery which is going to fetch me only the duplicated records so it's going to fetch me the two duplicated records okay and then I'll delete only those two records okay I'm using the CT ID which is kind of like a unique identifier for every record which is present by default in every table in post SQL okay and the third solution is I'm deleting using the window function row number okay so using the row number window function I'm trying to provide a unique row number for every record and wherever the row number is more than one because I'm partitioning based on the model name and the brand if if there are duplicate records based on model name and brand the row number will be more than one and wherever it is more than one I will fetch those records and I'll delete all of those records okay so this is my three solutions to delete duplicate data in a table now let's move on to the problem number two or the query number two the query number two is basically to display the highest and lowest salary corresponding to each employee record okay so I have been given an employee table it has four columns so employee ID employee name Department name and the salary so what I need to do is in each department I need to identify what is the highest salary earned by an employee in each department and what is the lowest salary earned by each an employee in each department okay now for example if you see the department ID so you see I have three records here and the last record here and in these four records the lowest salary is I think 2,000 earned by Robin and the highest salary I think here is earned by Kabir that is 8,000 right so I need to come up with an output which is going to add two new columns highest salary and lowest salary and corresponding to each department the highest salary should tell me what is the highest salary earned by each employee and the lowest salary column should tell me the lowest salary earned by each employee okay so this is my requirement now in order to solve this problem I'll show you the solution uh it's a very simple solution I'm going to be using the window function and I'm using the Min and Max function as window function now if you are not aware Min and Max are actually part of aggregate functions in SQL but you can use aggregate functions as window function if you basically use this Over clause okay so I'm saying fetch the max of salary okay but I'm using the over so this means that SQL is going to run this Max function as a window function okay so basically it means that what does window function do it's going to create separate windows or separate partition of Records right and then it's going to apply this Max function for each of that partition separately so here I'm basically partitioning the data based on the department so I have four departments admin Finance it and HR so it's going to create one window or one partition for each of these departments and within that department it's going to see what is the max salary earned okay and that will be displayed in the highest salary for each department and similar L for the lowest salary I'm using the minan function So within each of this department it's going to fetch the lowest salary and it's going to display that lowest salary here okay now one additional thing that I'm doing here is whenever you're using the Min uh aggregate function as window function you will probably have to use this Frame Clause now what you see here this basically called as a frame Clause it kind of makes sure that when the aggregate function or this whatever the function that you're using you are applying uh a window to it it's going going to make sure that it gets all the records in the T in the data set okay so I'm basically using range between unbounded proceeding and unbounded following this means it kind of gets access to all the records when it's trying to find the minimum of the salary okay now I'm not going to explaining this Frame clause in detail because Ive made a separate video about window functions where I have explained in detail how this uh uh frame Clause works I'll leave the link to that video also in the video description so if you want to learn more about frame Clause you can definitely check out that video okay now this is basically my solution to solve this problem now before I can move on to the next SQL query let me first talk about one of the best platforms that you can find online to learn SQL and the platform is learns ql.com now the reason why I say that this is one of the best platforms to learn SQL is because I have personally been using this platform and seeing this platform for more than couple of years and the best part about this platform is the quality of the content contents that is present in this platform so so the different data sets the different scenarios the different examples that they use to explain different concepts are great and it's not just that you will be learning theoretically all the SQL Concepts but you'll be practically solving so many different SQL queries to learn all the different concepts depending on what you want to learn in SQL whether you want to learn let's say all the basics Concepts maybe about joints or you want to learn about window functions or you want to learn SQL just for data analysis or let's say you want to learn all the advanced concepts in SQL or let's say you just want to practice solving SQL queries so depending on what you want to learn you will find some course available on this platform which you can just take and learn SQL and just to tell you how good this platform is my wife who comes from a completely non-it background when she was learning SQL this was the platform that she used to always come back to she had taken several different courses on Udi corsera Etc but this is the platform that she used to like the most and I used to ask her why do you come back to this platform so much and she used to say that she finds it very easy and interesting to learn on this platform the reason is the user interface is very good it's very interesting very intuitive you kind of will exactly know how to navigate through different sections very easily the examples the scenarios are very engaging you will find it interesting and you will be solving and writing multiple different SQL queries so you kind of will find it interesting to spend time on this platform now the best part is that currently for the next couple of days there is a black week sale going on with which you can get around 72% off so I think it's a pretty good time to check out this platform and to learn SQL from this platform and one important thing is that recently in learns ql.com they have introduced this new certificate the certificate for SQL competency where anyone even if you have not purchased any course for free you can just sign up to the platform and you can take this competence test okay SQL competence test now what this kind of does is it's kind of going to test your knowledge on SQL so if you want to know how good you are with SQL then this is a great certificate that you can have okay so you can just go and you can sign up and you can take this assessment and if you score I think 70% you will get the certificate but let's say you fail and you do not get 70% then you can retake the test after 30 days now let's get back into our video now let's move on to the third query the third query that I have is basically to find the actual distance so you can see that I have been given this data or this given input table it's a cards table you can see that I have information about cards so there is three different columns there is different cards car 1 Car 2 car three these are the different days and these are the distance it has traveled but this is what you what you see here is basically the cumulative distance so what this means is the car one on day one it traveled 50 km the same car on day two it's mentioned as 100 km but it is cumulative distance that means the actual distance the car traveled on day two would be the distance this this distance day two distance minus the day one distance and that would be 50 right same way the same car that is car one on day three it's mentioned like it the cumulative distance is 200 but the actual distance that the car traveled only on day three would be 200 minus 100 that is 100 right and that is exactly what you need to come up with so you need to write a query which is going to provide a last column or a new column which is the actual distance the car traveled on each day okay so here you can see that car one traveled 50 kilm on day one car one traveled 50 km on day two on day three traveled 100 km and the same thing you need to do for the remaining cars okay now I hope you understand this the basic thing is the given distance is cumulative distance you need to find the actual distance okay now in order to solve this problem the solution is actually very simple as you can see the solution is like one or two lines and what I'm basically doing is I'm using the lag lag window function okay now what I'm basically doing is my intention was every time if I want to find the actual distance I need to to get the cumulative distance and subtract it with the cumulative distance from the previous day okay so what I'll do is I'm taking the cumulative distance here for every record minus I'm taking the cumulative distance from the previous record in order to fetch the data from the previous record we always use the lag window function right I'm saying go one record prior and if there are no previous record then by default it is zero because for the very first record there would be no previous record right so that time the lag is going to return zero so it will be 50us 0 will return 50 okay so this is basically the concept nothing much here I'm partitioning the I'm partitioning the data based on cards because I'm I'm kind of like creating a partition for each car and then I'm finding the cumulative distance from the previous day and subtracting it uh with the cumulative cumulative distance of the current day okay so this is actually my solution now I might be going a little fast because I want to keep this video as short as possible but you can definitely go through these Solutions and understand what's happening your yourself okay now quickly let's move on to the query number four and the query number four that I have is basically I have been given an input and I need to derive the expected output okay now what I have is I have a table which is telling me the distance between two different cities so the source and the destination and the distance you can see that the distance between Hyderabad or Bangalore and Hyderabad is 400 km and the distance between Hyderabad and Bangalore is again 400 km and the same thing for Mumbai Delhi Delhi Mumbai 400 and Chennai Pune and Pune Chennai again 400 now if I look carefully I can say that the records are kind of like duplicated not exactly duplicated but these are redundant data right because you're basically mentioning the same information twice so what we need to do is we need to eliminate one of these records so you just tell the distance between Bangalore and Hyderabad as 400 Chennai and Pune as 400 and Mumbai and Delhi as 400 okay I'm sure you have seen this query probably many different times in LinkedIn or many other places but it's a very common question that you can expect during interviews now in order to solve this problem what I'm going to be doing is I'm just using the self-join concept in SQL okay now this is basically my solution what I'm doing is I have this data but in this data that is given I do not have any unique identifier I need a unique identifier for each of these record because I'm going to use that to eliminate one of the record when I'm getting my output so so what I'll do is I'm using the CT the first thing that I'll do is from this table I'm just adding a new column row number so row number window function will just add a unique row number for every record right so I'm adding this so once I have this unique identifier then what I'll do is this whole CT I'm just using it twice so once I'm just calling it table one the second time I'm calling it table two T2 okay and then what I'll do is so you need to imagine this this basically depends on how much you can imagine and understand imagine this same same table is present twice okay and I'm doing I'm joining the source of table one with the destination of table two so this record will join with this record and the source of or basically the destination of table one with the source of table two okay so I'm joining this with this and this with this so when I if I just had these two join condition then I'll still get all of these records but then I have one Rec one condition such that I only fetch when the row number of the table one is less than the row number of table two that means only one of these records will get fetched and the other record will never get fetched because of this particular condition okay and that is when if I run this query you can see that from six now I'm only getting the three records which is actually my expected output okay so this is basically the problem okay I hope it's it's you are able to understand what I was trying to explain now I have I think made a separate video about this particular query I if I find that video I'll try to leave a link to that video in the description so if you want to get more details and understand self jooin in detail then you can probably watch that video okay now let's move on to the query number five the query number five that I have is kind of like ungroup the given input data okay now this is also pretty commonly asked especially if you're attending Fang interviews then these are the kind of question that you can expect okay now you can see that I have given an I have been given an input table it has ID item name and total count and you can see that have water bottle they are saying there are totally two water bottles tent there are totally one tent and apple there is totally four apples okay what I need to do is I need to ungroup this data meaning if there are two water bottles I need to have water bottles mentioned in two different rows okay if there is one tent then I need to have the tent mentioned in one different row and if I have four apples then there should be four rows with that value Apple okay so how do you kind of like ungroup this data into separate rows okay you know order to do this what I'm going to do is I'm just using the recursive SQL functionalities so you can see that I have this travel items table it has three records right and what I'm doing is I I'm using recursion now I'm not going to be explaining recursion in detail but I have made a separate video about recursive SQL queries where I have explained in detail how recursion works okay if you want to understand that better I'll leave the link to that video in the video description okay so but quickly just to explain you now as part of recursion you write this recursive keyword I'm using post SQL okay and you give a name to your city and then you write two different queries okay which should be separated by a union all okay or a union the first part of this query this is called as the base query inside this query what I'm doing is I'm basically fetching the data as it is okay I'm using this column level just to understand in each level what data I'm fetching okay and then once I have my base query that is all of these records then in the second query here this is basically the query that execut from the second iteration okay in the first iteration only this query gets executed the base query then from the second iteration onwards only the below part of the query gets executed now whenever this query gets executed what I'm basically doing is I'm joining the result from the previous iteration that will be returned from CT I'm joining it with my actual table the main table and then I'm joining it using the unique identifier that is ID and item name right and then I'm putting a termination condition here such that whenever the total count will become zero it kind of will terminate so this will basically execute until the total count is greater than zero okay or greater than one okay now how does this total count value change is because in this query here you can see I'm kind of substracting one value in each iteration okay in the first iteration total count so let's say for this water bottle in the first iteration total count is two in the second iteration total count will become 2 - 1 1 in the third iteration total count will become become zero but zero is not considered so it will not be shown okay and the same thing will happen for other items so let's say if I just execute this whole query now okay and I have this level just to tell you in each iteration what happened you can see that in the first iteration here okay so I returned all these three records as it was okay because that was in my main table in the second iteration the water bottle will become 2 minus 1 so you can see that uh water bottle is displayed here in the second iteration apple is also displayed but I think there was another tent tent was only one in the second iteration tent is not present right when it comes to the third iteration water bottle also will become zero so that is also not displayed but Apple will still be there and the same thing will happen in the fourth iteration okay I hope you are able to understand what I'm trying to explain if you need to understand recursion more in detail then you should definitely watch my recursive SQL query tutorial video okay I'll leave the link to that in the video description okay now this I think was the fifth SQL query now let's move on to the sixth SQL query that I have and the sixth SQL query is to derive IPL matches okay so basically here we have two different uh queries that we have been asked so what we need to do is we have been given an input table now if you do not know what is IPL it's basically a cricket league that happens once a year where there are 10 teams that participate and they play with each other okay so you have these are the 10 teams that is mentioned they uh Team Code and their team name okay I need to come up with a query that is going to tell me each team has to play with the other team okay so here I have each team should play with the other team only once and then I also need to write another query where each team is going to play with the other team twice okay so this is the expected output I have actually there are much more records than what you see here okay but I just showed you some sample records okay so this is the sample uh output for when the team plays the other team just once and this is the sample output when the team place the other team twice okay now how do I solve this problem so let me go back to my post SQL PG admin tool and here I have my table the team's table there are 10 records here okay now in order to solve this problem the for for the first problem that is how do I make sure that every team plays the other team just once okay the solution is again simple the first of all what I need to do is I am going to be using the self join as you can see here okay and I do not have a unique identifier in this table so the very first I'll do is in the CT I'm going to create the same table or basically quy the same table but I'll add a unique identifier by using the row number window function okay once I have the unique identifier then I'm just joining that same table to itself and I'm just saying whenever I'm joining the ID from the first table should be less than the ID from the second table that is the team versus the opponent okay this way this one record will never match with the other uh same record from the other table so this team will only play with the remaining nine teams only once okay and that is how this query will work and when I execute this query you will see that I'll get 45 records okay because each of the 10 teams played with the other team just once okay so there are totally 45 matches okay now if I have to make sure that each team plays the other team twice then the only change in the whole query is to just change this operator instead of less than two symbol I'm just making it not equal to okay when I make it not equal to theany complete meaning of this join kind of changes okay now what happens is every team will play with so when I have let's say this query here okay this is my first table I'm joining this table to itself that is I'm calling it like the openend table right what happens is this record will join with all the other records except for this same record and if you can imagine what happens is after each iteration it will not it will basically not match the current record that it is basically trying to match but other than that it will match with every other record okay I'm not sure if I'm explaining this properly but I have made a separate video about this particular query as well where I have explained in detail how this actually works okay because if I try to explain this in detail I'll need a lot more time so if you want me to make a separate video to explain this in detail let me know in the comments below okay so this is basically my query number six okay and it's a very common question that you can expect here I have IPL matches but it can be something similar to this as well okay now let's move on to the question number seven the query number seven and this is where you see that you have been given a table it has three columns it's sales date sales date the customer ID and the amount you need to come up with an output which looks something like this okay now as soon as you look at this query you kind of probably get an idea that this is where you will need to do a pivote right a pivote or probably you could do it using the case statement okay so you need to transform the roow level data into column level data okay now in order to solve this problem what I am doing is as I already told you we can solve it using two different ways okay one is you can use the pivote function but since I'm using post SQL pivote is not supported in post SQL but cross tab is supported cross tab is a function which kind of converts row level data into column level data it's kind of similar to pivote but the syntax is different okay so you can do solve this problem using this cross tab function or you can also solve it by using the simple case statement okay but let's say if you're using some other databases maybe Microsoft SQL server or Oracle then you can use pivote now in my in my file where I'm going to be sharing with you the solution you will find the solution for other databases as well okay so using pivote now I'll not be explaining this query in detail because this is pretty big and I think I have made a separate video about it I'll leave the uh description of in the description I leave the video link where you can understand this better okay but what cross tab basically does in the most most simplest of terms cross tab function takes two arguments the first is the SQL query with this SQL query should have three columns the first is the unique identifier second is the number of uh columns that you need to come up with in your output and the third column is a value that will be placed in each of that newly created columns okay and then here I'm basically this is kind of like the output columns what it will be called okay along with the data types okay and then here I'm just I think I will be getting null values I'm just replacing it with zero and then I'm just display displaying the final values to handle I think I have some dollar symbols to handle and concatenate all of that I'm doing that okay now if I just run this query and if I show you whether it actually works but if I run this uh and I need to minimize this you can see that if I run I'm getting the output how I want it okay so this is basically the query using the cross tab same thing can be done by using pivot but post SQL does not support pivot but in Oracle and Microsoft SQL Server you will need to use peot and I have placed that solution in my file okay so this is my query number seven now let's move on to query number eight query number eight is basically find the hierarchy okay you are given I think an employee table it has an employe ID name manager ID salary and designation okay we have been asked to find the hierarchy of employees under a given manager Asha okay so here I have a manager Asha you can see this row number seven right and her manager ID is one and asha's employee ID is 7even I need to find the hierarchy of employees under Asha so how many people are actually working under Asha now I can see that asha's EMP or employee ID is seven and in the manager ID column if I look for seven I can see that I have two places where I have seven so Michael and arind are the two employees whose managers are manager is seven that means Michael and arind work under Asha right but then if I see that Michael has an employ ID of five and five is present here in the manager ID column that means Michael is also a manager who has three employees under him Satya Gia and David right so the total number of employees under Asha would be Michael arind and these three that is Satya G and David so I need to come up with a query which is going to display that okay as shown here in the expected output now in order to solve that problem again I'll be using recursive SQL queries so the concept is again simple I just say in my base query I fetch the data for Asha I take uh the I think from this city I'm taking the ID of Asha that is seven okay and I'll search for this seven under the manager ID column in the employee details table so and I'm having the and this is because it's a recursion it will kind of recursively look for that manager ID in that employee details table okay so when I run this whole query you can see that I'm getting all the employees under Asha in this format okay so this is basically my solution using H uh recursive SQL queries okay now let's move on to the query number nine the query number nine is basically to find a difference in average sales okay now you can see that I have been given a sales table and this sales table is pretty big it has 2,823 rows but here I'm just showing you some sample data okay we need to write a query which is going to find the difference in average sales for each month of 2003 and 2004 okay so I have the sales data here and I have the year data here and I think I have the month ID here I also should have the order date here right for each month I need to find the average sales for the year 2003 and 2004 and then compare it between these two years so I here I basically my output should be 12 rows one row for each month okay and this is the difference in the sales that happened between the Jan 2003 and Jan 2004 same way this is the difference in the sales that happened in Feb 2003 and 5 2004 okay so I need to come up with a query like this okay now in order to solve this problem what I'm basically doing is I'm using the concept of self jooin and city now if I show you the sales order data you can see that I have 2,800 plus records I have I think the sale uh column here okay and then the order date column here from where I can fetch the month and the year or I can also use the month ID and the year ID to fetch the month and the year okay the first first thing that I'm doing is I'm writing a subquery here and putting it inside the CT and what this subquery is basically doing is I am taking the data from this table only for the years 2003 and 2004 and I'm grouping the data based on the year ID the month ID basically I'm also using month I'm taking month ID because I need to sort the data based on the proper month ID and that is why I'm having the month ID but I'm grouping the data mainly based on year month and then finding the average sales okay so for each month of each of these two years I'm getting the average sales once I have that what I'll do is I'll put this whole CT in my main query and I'm using it twice so I'm using a self joint I'm calling it this once for year 2003 and second one for year 2004 okay I'm joining it based on the month because each of this year the months will be common right and then I'm how do I say I want one table to only be fetching data for the year 2003 and other only for 2004 I just put that by using this filter using the year ID column right and I'm joining it using the month and then once I join it using the month I'll just display that month and I'm basically taking the I'm kind of doing a substraction okay so the average sales per month from 2003 minus the average sales per month from 2004 okay and this will always be for the correct month because I'm joining using the proper months here right so this will give me the difference but some of the months there might be negative values in order to eliminate the negative values I'm using the ABS apps uh function this will eliminate the negative values and then I think there'll be lot of decimal points hence I'm using the rounding so that I only get two decimal points okay so if I run this now you can see that for each of these 12 months I am getting the difference that I actually wanted okay so this is basically the solution to this particular query I hope it's clear now let's move on to the last query that I have and this is the kind of query that you can generally expect a lot during interviews okay the the query is basically basically Piza delivery status now it has a pretty long problem statement so let's first understand the problem statement and then we will see how to solve it a Piza company is taking orders from customers and each Pisa ordered is added into their database okay so a customer is ordering a Piza and all the details are entered into a database each order has an Associated status like created submitted and delivered now you if you see the input table here I have the customer name order ID and the status so John is a customer he has made two orders J1 and J2 and his status is delivered David has made three orders his status for one of them is submitted the other one is delivered the other one is created Smith made one order and his status is submitted Krish made another order whose status is created okay so these are the three different status you can have when a customer makes an order okay and then they are saying and Order's final status is calculated based on this based on these four rules okay so this is the order when when the customer makes an order this is the three different status that you can have okay but the final status of that particular order depends on these four rules and the rules are when all orders of a customer have a status as delivered the customer's order has a final status as completed okay so that means JN has two orders and both are delivered that means you can say that the final status for John would be uh that is completed right and that is basically what you want in your expected output you can see here for John the final status is completed now the second rule is if a customer has some orders that are not delivered and some orders that are delivered the final status is in progress that means if there is any customer whose some of the orders are delivered but some other orders are having some other status then their final status should be in progress and for that example is David you can see that David has one order that is D2 which is delivered but other two orders one is submitted and one is created so in this case for David the final status should be in progress Okay the third one is if all customers orders are submitted the final status is awaiting progress okay so if all the orders of a customer is submitted let's say I have Smith and he has only one order and it is submitted then his final status should be awaiting progress so for Smith it is awaiting progress here in the final output and the last one is otherwise the final status is awaiting submission so anything other than this this final status should be awaiting submission okay so how do you write a query to handle all of these different statuses okay now let's look at the solution and you can see that I have the customer orders table created it has seven rows with information about I think four different customers now what I have basically done is you can see that I have written four different queries so if I just maximize this you can see that I have one query to handle the status delivered okay or basically to to get the status completed I have another query to handle the status in progress I have another query to handle the status awaiting progress and the final query to handle the last status I writing submission okay what I'm doing is in each of these queries I I'm basically implementing the logic that is mentioned in each of these point so for example the first point is when all the customer orders are delivered then the customer final status is completed so if everything is delivered so what I'm saying is from the customer orders table if the status is delivered and I'm checking if there are no other records not exist if there are no other records with status submitted or created that means for this particular customer you can see that I'm joining based on customer for this particular customer if he has one record we delivered and there are no other records with these two statuses then this we can say that all the status all the record of this particular customers would have the status as delivered only and that means the final status can be completed okay this is what I'm doing the next one is if a customer has some orders delivered and some other orders may be some other status then the final status should be in progress and that is what I have implemented in this query number two here or the the second query here okay so what I'm doing is I'm taking the customer where any one of the status any one of the record status is delivered and I'm also checking exist okay the only difference between this query and this query is that here I'm using not exist here I'm using exist I'm checking along with this record which is delivered there should also be some other record for the same customer which can either be submitted or created if there is then that for that particular customer the final status will be in progress okay and the same thing I'm doing for the other two queries I'll not explain this because I think this is self-explanatory if you understand these two you will you probably understand these two as well okay so these are the 10 SQL queries that in my opinion if you can solve it and if you know to solve these type of queries then you can be rest assured you will be able to solve almost any type of queries in any interviews I hope you like this video and if you did and if you have faced any of these top 10 queries in your interviews let me know in the comments below thank you so much for watching and see you soon in the next one bye
Info
Channel: techTFQ
Views: 225,735
Rating: undefined out of 5
Keywords: sql, learn sql, sql query, sql queries, top 10 sql queries, sql interview queries, sql problem, sql interview problem, best sql queries, most common sql queries, solve sql queries, practice sql queries, sql techtfq, techtfq sql, techtfq
Id: ZML_EJrBhnY
Channel Id: undefined
Length: 36min 33sec (2193 seconds)
Published: Wed Nov 22 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.