SELECT retrieves rows and columns from one or more tables or views.
SELECT lets you read data from tables or views, returning only the columns and rows you need. It is the foundation for reporting, analytics, and application logic.
Start with SELECT, list columns, add FROM with the table name. Run it to see results.
SELECT *
FROM Customers;
Name the columns instead of *.This improves performance and readability.
SELECT id, name, email
FROM Customers;
Use WHERE to return only matching rows.
SELECT *
FROM Orders
WHERE total_amount > 100;
ORDER BY arranges rows ascending (ASC) or descending (DESC).
SELECT *
FROM Orders
ORDER BY order_date DESC;
TOP restricts the result set to a specific number or percentage.
SELECT TOP 10 *
FROM Products
ORDER BY stock DESC;
JOIN combines rows from related tables.Always specify a join condition.
SELECT c.name, o.id AS order_id, o.total_amount
FROM Customers AS c
JOIN Orders AS o ON o.customer_id = c.id;
List only needed columns, use explicit aliases, index filter columns, and avoid SELECT * in production queries.
Missing WHERE clause can update or read all rows—add filters.Forgetting table aliases causes ambiguous columns—always alias joined tables.
Anytime you need to query, filter, aggregate, or prepare data for further processing in SQL Server.
.
No. SELECT is read-only. Use INSERT, UPDATE, or DELETE for changes.
Use aggregate COUNT(*): SELECT COUNT(*) FROM Orders;
By default, SQL Server applies shared locks that allow concurrent reads but block writes until the read completes.