SQL Basics (SELECT, WHERE, ORDER BY)
SQL Basics (SELECT, WHERE, ORDER BY)
Structured Query Language (SQL) is the standard language used to interact with relational databases. It allows you to retrieve, insert, update, and delete data stored in tables. Learning SQL basics is essential for working with databases and is one of the most important skills in DBMS.
In this lesson, you will learn the fundamental SQL commands such as SELECT, WHERE, and ORDER BY, which are used to query and filter data efficiently.
What is SQL?
SQL stands for Structured Query Language. It is used to communicate with relational databases like MySQL, PostgreSQL, and Microsoft SQL Server.
With SQL, you can:
- Retrieve data from tables
- Filter records based on conditions
- Sort data in a specific order
- Perform calculations on data
SELECT Statement
The SELECT statement is used to retrieve data from a table.
Syntax:
SELECT column_name FROM table_name;
Example:
SELECT Name FROM Students;
To select all columns:
SELECT * FROM Students;
WHERE Clause
The WHERE clause is used to filter records based on a condition.
Syntax:
SELECT column_name FROM table_name WHERE condition;
Example:
SELECT * FROM Students WHERE Age > 18;
Common operators used in WHERE:
- = (equal)
-
(greater than)
- < (less than)
- AND, OR
ORDER BY Clause
The ORDER BY clause is used to sort the result set.
Syntax:
SELECT column_name FROM table_name ORDER BY column_name;
Example:
SELECT * FROM Students ORDER BY Name ASC;
Sorting options:
- ASC (Ascending order)
- DESC (Descending order)
Combining SQL Clauses
You can combine multiple clauses for advanced queries.
Example:
SELECT Name FROM Students WHERE Age > 18 ORDER BY Name ASC;
This query filters students older than 18 and sorts them by name.
Real-World Example
In an e-commerce database:
- Retrieve all products
- Filter products by price
- Sort products by rating
SQL helps in handling such operations efficiently.
Why Learn SQL Basics?
Learning SQL helps you:
- Work with real-world databases
- Build backend applications
- Perform data analysis
- Crack technical interviews
FAQs
What is SQL used for?
SQL is used to manage and query data in relational databases.
What does SELECT do in SQL?
SELECT retrieves data from a database table.
What is WHERE clause?
WHERE filters data based on specific conditions.
What is ORDER BY in SQL?
ORDER BY sorts the data in ascending or descending order.
Where can I learn more courses like this?
Click here for more free courses



