SQL Select statement is used to retrieve records from one or more tables. It is the most commonly used DML statement.
SQL SELECT Syntax
To retrieve all the records from the Table.
Select * From table_name
To retrieve specific columns in the records from the Table.
SELECT column_name(s)
FROM table_name
Note: It is advised that you use the column names instead of asterix(*) in the select statement when quering large data from tables.
This produces result faster and prevents data from unnecessary columns.
Database Tables
A database contains usually one or more tables. Each table is identified by a name (e.g. "Customers" or "Employees"). Tables contain many records with data.
A table is a datastructure where information is stored in the form of rows and columns.
Below is shown the "Customers" table:
C001 |
Fredrick Johnson |
FJohnson@yahoo.com |
Berkeley Gardens 12 Brewery |
London |
WX1 6LT |
UK |
C002 |
Mary Davidson |
Mary@gmail.com |
35 King George |
Madrid |
28023 |
Spain |
C003 |
George Clooney |
George@hotmail.com |
Obere Str. 57 |
Berlin |
12209 |
Germany |
C004 |
David Louis |
David@mail.com |
2743 Bering St. |
NewJersy |
07019 |
USA |
C005 |
Johnny Anderson |
Johnny@gmail.com |
55 Grizzly Peak Rd. |
NewJersy |
07019 |
USA |
C006 |
Paul Henriot |
PaulHenriot@yahoo.com |
59 rue de l'Abbaye |
Paris |
51100 |
France |
C007 |
Henry King |
Henry@mail.com |
120 Hanover Sq. |
London |
WA1 1DP |
UK |
C008 |
Robert John |
Robert@gmail.com |
87 Polk St. Suite 5 |
San Francisco |
94117 |
USA |
Type or Copy the SQL into the Text Editor, click the "View Result" button, to see the result.
The Select Statement Example
To retrieve all the records from the Customers table.
Select * from Customers ;
Retrieve Customer details with the name Fredrick Johnson
Select * from Customers
where CustomerName ='Fredrick Johnson';
Retrieve all customers from USA
Select * from Customers
Where Country = 'USA';
SQL in Text Editor: