SQL Basics - Ordering

Details
Title | SQL Basics - Ordering |
Author | BeardedDev |
Duration | 25:46 |
File Format | MP3 / MP4 |
Original URL | https://youtube.com/watch?v=K1MyfxYFG2c |
Description
Another video brought to you by BeardedDev, bringing you tutorials on Data Engineering, Business Intelligence, T-SQL Programming and Data Analysis.
If you like the video you can support me on Patreon, https://www.patreon.com/beardeddev
Prerequisites
Check out this link to install SQL Server: https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server?view=sql-server-ver15
Click here to install SQL Server Management Studio: https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver15
Check out this link to install Adventure Works Database: https://docs.microsoft.com/en-us/sql/samples/adventureworks-install-configure?view=sql-server-ver15&tabs=ssms
Have you ever thought "how do I get started with SQL?", "how do I find out if SQL is for me?" then this video aims to answer those questions, it will allow you to start writing SQL queries straight away.
If you are not familiar with writing basic queries check out part 1 here: https://youtu.be/k3CCFnICg5Q
In this video we cover how to returned ordered data, that is using the ORDER BY clause of the SELECT statement, you learn how to order by single columns, multiple columns, use different orders.
The video also covers using TOP to limit results to a specified amount, a certain percentage and how to include ties when working with TOP.
This tutorial is going to be part of a short series that aims to get you up and running straight away, writing queries and potentially hungry to learn more.
Whether you are a data analyst look to develop your skillset or a front end developer curious about how databases work or a recent graduate then I'm sure you will find something here that will help.
If you have any difficulties setting up the environment of would like me to produce a tutorial then please let me know in the comments below.
Code Samples - this is not complete but you can copy and paste and change as necessary
Replace any words with [] with symbols, cannot add angle brackets in description
SELECT
CustomerID
FROM Sales.SalesOrderHeader
ORDER BY CustomerID;
SELECT
CustomerID,
TotalDue
FROM Sales.SalesOrderHeader
ORDER BY
CustomerID,
TotalDue;
SELECT
CustomerID,
TotalDue,
SalesOrderID
FROM Sales.SalesOrderHeader
ORDER BY
CustomerID,
TotalDue,
SalesOrderID;
SELECT
CustomerID,
TotalDue
FROM Sales.SalesOrderHeader
ORDER BY
TotalDue DESC;
SELECT TOP(10)
CustomerID,
TotalDue
FROM Sales.SalesOrderHeader;
SELECT TOP(10) PERCENT
CustomerID,
TotalDue
FROM Sales.SalesOrderHeader
ORDER BY TotalDue DESC;
SELECT TOP(2) WITH TIES
CustomerID,
TotalDue
FROM Sales.SalesOrderHeader
ORDER BY TotalDue;
SELECT TOP(1)
CustomerID
FROM Sales.SalesOrderHeader
ORDER BY TotalDue DESC;