Vikas Rajput
Vikas Rajput

@vikasrajputin

8 تغريدة Dec 06, 2022
Introduction to ORDER BY, GROUP BY and HAVING clause in SQL
🧵👇
1. ORDER BY
- Order by clause is used to sort query results in ascending or descending order.
Example:
- Below are two queries that are sorting results in descending and ascending order using DESC and ASC respectively.
2. GROUP BY
- It is used along with aggregate functions (SUM, COUNT, etc.) and groups the column into distinct values, and shows aggregated results against each value.
Example:
- Below query aggregates the CITY column and shows the total employees in that city.
3. HAVING
- Having clause is used to add a condition to queries where aggregate functions are used.
- Having clause is applied after the aggregate functions are computed (Unlike a where clause, which is applied before) and hence they're used to filter the aggregated results.
Example:
- Below query uses the Having clause which is applying conditions to aggregated results and returning records with cities where more than employees are living.
That's a wrap!
I'm purposefully not showing the results of queries and would love you to give it a try and let me know your feedback in the comments.
Do you know?
I am also starting content creation on LinkedIn & Instagram:
Follow me below on handles to support my work:
linkedin.com
instagram.com
More details👇
Namaste, I'm Vikas!
Every Mon, Wed & Friday - I write a thread on Backend Development.
1. Follow me @vikasrajputin to read all my future threads
2. RT the tweet below to share this thread to help spread the knowledge

جاري تحميل الاقتراحات...