SQL SELECT

The SELECT statement is a DQL (Data Query Language) command used to retrieve data from one or more tables in a database.

👉 In simple words: SELECT is used to view or query data from a table without changing it.

Explanation of Clauses:
SELECT → Specifies which columns to retrieve
FROM → Specifies the table(s)
WHERE → Filters rows based on a condition
ORDER BY → Sorts the results
GROUP BY → Groups rows (used with aggregate functions)
HAVING → Filters groups (used with GROUP BY)

Simple SQL Syntax

SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column
GROUP BY column
HAVING condition;

Select all columns

SELECT * FROM Students;

Select specific columns

SELECT Name, Age FROM Students;

Select with condition

SELECT * FROM Students
WHERE Age > 18;

Full Example Using All Clauses: Get CustomerID, Product, and Total Amount, for customers whose total amount > 10000, sorted by total amount descending:

SELECT CustomerID, Product, SUM(Quantity * Price) AS TotalAmount
FROM Orders
WHERE Price > 1000
GROUP BY CustomerID, Product
HAVING SUM(Quantity * Price) > 10000
ORDER BY TotalAmount DESC;


Quick Tip:
Always remember:
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY
This order is logical execution, not the order you write clauses.

Simple Definition
SELECT is a SQL command used to query and retrieve data from one or more tables based on specified conditions.


Topics