Solve complex SQL queries using patterns - Very easy technique | Part - 1

preview_player
Показать описание

Do you understand SQL but still cannot write SQL queries correctly ?
Are you afraid to switch jobs because of the SQL interview rounds or have you failed SQL Interview earlier ?
If you are someone who understands SQL and need more confidence to solve SQL queries correctly, I would like to share my recent online course especially created for you.

In this video I will address the question if you really need to solve 100s of SQL questions to clear your next SQL interview ?
In the last few weeks I have solved lots of SQL questions available on the platform like DataLemur & Stratascratch.

I will share the links in the description box below for easy reference.
After solving so many questions I could clearly see some SQL patterns coming out of those different queries.
Also I know many candidates they feel they knew the answer to SQL question but at that moment it did not come into their mind.
So I asked myself a question if there is a better way to approach and solve SQL queries ?

Hi Everyone !
My Name is Nitin and welcome to my channel.
In this video I will share the 9 SQL patterns I have observed after solving 100s of SQL queries in the last few weeks.
Additionally this also includes my 14+ years of professional experience as Data Analytics consultant.
I wish to share a disclaimer at the start: I am not saying that you should not practice SQL queries. Intent of this video is to give you an alternate way to approach any SQL problem. If this helps you in handling SQL queries in a more systematic way I will feel that I am successful in conveying my message.

Let me share the 9 SQL patterns I have observed that can help anyone in solving SQL queries.

I observed that any SQL query which I was solving was using one or more of these SQL Patterns. I have also listed down sub-categories of each pattern which were observed very frequently.
The 9 SQL patterns are WHERE ...
In this video we will look into each of these patterns with few examples to help you understand more about it.

Where condition is used to filter incoming rows in the SQL. Some of the common sub-patterns I observed in WHERE condition are:
Say you have to compare one or more column values to a hardcoded value like in the first example here you can see status- Completed.
Similarly, you can have IN or NOT IN conditions for one or more columns in the WHERE clause. Refer to second example for easy reference.
Third sub-pattern is you check the value of a column to be NULL or NOT NULL. Please do not use equal to with NULL values. NULL is always compared using IS NULL or IS NOT NULL.
Fourth sub-pattern is WHERE clause with a subquery. You have to compare a column value with a output of scalar sub query that returns one row only.
You may also have to use EXISTS or NOT EXISTS in the WHERE condition
the Sixth most common sub pattern I observed in WHERE condition is where you compare one column value with another column value or a derived value.

So next time when you have to apply a WHERE filter and you are aware of these sub-patterns you can make a informed decision while writing SQL query.
Let's move to the next pattern which is ORDER BY

ORDER BY is used to sort the output result as per the columns mentioned in the ORDER BY clause.
You can have one or more column names in the order by clause.
you can sort the values in ascending order i.e. smallest to largest
or descending order which is largest to smallest.
The keyword used to refer to ascending is asc and for descending is desc.
default value is ascending so you don't have to explicitly write it if you don't want to.
You can also use positional assignment in the order by clause as mentioned in the 4th example here
You can also have derived values in the ORDER by clause.
Since order by clause is one of the last construct in SQL execution order is it possible to use derived values in it as well.
The last example shows here that we have used a derived value in the order by clause.

If this is clear to you let's move to the next pattern which is LIMIT.
Рекомендации по теме
Комментарии
Автор

Very informative 👌👌. Thanks for uploading this video. Please continue this series.

sneha
Автор

Hi thanks for you're effort, can you help in SQL3 Please 🙏🙏🙏🙏🙏🙏🙏🙏🙏 i need it so bad

fatimaezzahrasoubari
welcome to shbcf.ru