SQL SELECT Statement
The SQL SELECT Statement
The SELECT statement is used to select data from a database.
Example: Return data from the Customers table:
SELECT CustomerName, City FROM Customers;
Syntax
The syntax for the SELECT statement is as follows:
SELECT column1, column2, ...
FROM table_name;
Here:
- column1, column2, … are the field names of the table you want to select data from.
- table_name represents the name of the table you want to select data from.
Demo Database
Below is a selection from the Customers table used in the examples:
| CustomerID | CustomerName | ContactName | Address | City | PostalCode | Country |
|---|---|---|---|---|---|---|
| 1 | Shree Tiffins | Ravi Kumar | Dadar East | Mumbai | 400014 | India |
| 2 | Kolkata Sweets | Aarti Kapoor | Park Street | Kolkata | 700017 | India |
| 3 | Hyderabad Biryani House | Ali Khan | Jubilee Hills | Hyderabad | 500033 | India |
| 4 | Punjab Dhaba | Sandeep Singh | Sector 15 | Chandigarh | 160015 | India |
| 5 | Delhi Delights | Neha Sharma | Connaught Place | New Delhi | 110001 | India |
Select ALL Columns
If you want to return all columns, without specifying every column name, you can use the SELECT * syntax:
Example: Return all the columns from the Customers table:
SELECT * FROM Customers;
Example 1: SELECT Specific Columns
To select specific columns, you can list them after the SELECT keyword:
SELECT CustomerName, City FROM Customers;
