SQL - SELECT statement
SELECT statement is used to select the records from the table. You can specify the wild card (*) to display all the fields. You can limit the number of rows and you can sort by ascending or descending. A couple of sample SQL SELECT statements are given on this page:
SELECT * FROM Students SELECT FirstName, LastName, Age, City FROM Students SELECT FirstName, LastName, Age, City FROM Students ORDER BY LastName SELECT FirstName, LastName, Age, City FROM Students ORDER BY LastName DESC
The first query will return the following records:
No |
FirstName |
LastName |
Age |
City |
---|---|---|---|---|
1 |
David |
Alex |
19 |
San Francisco |
2 |
Ravi |
Sharma |
18 |
San Jose |
3 |
Surya |
Kumar |
17 |
Milpitas |
4 |
Saravanan |
Kandasamy |
18 |
Cupertino |
5 |
Senthil |
Kumar |
19 |
San Francisco |
The 2nd query will return the following records:
FirstName |
LastName |
Age |
City |
---|---|---|---|
David |
Alex |
19 |
San Francisco |
Ravi |
Sharma |
18 |
San Jose |
Surya |
Kumar |
17 |
Milpitas |
Saravanan |
Kandasamy |
18 |
Cupertino |
Senthil |
Kumar |
19 |
San Francisco |
The 3rd query will return the following records ORDER BY LASTNAME:
FirstName |
LastName |
Age |
City |
---|---|---|---|
David |
Alex |
19 |
San Francisco |
Saravanan |
Kandasamy |
18 |
Cupertino |
Surya |
Kumar |
17 |
Milpitas |
Senthil |
Kumar |
19 |
San Francisco |
Ravi |
Sharma |
18 |
San Jose |
The 4th query will return the following records ORDER BY LASTNAME DESC:
FirstName |
LastName |
Age |
City |
---|---|---|---|
Ravi |
Sharma |
18 |
San Jose |
Senthil |
Kumar |
19 |
San Francisco |
Surya |
Kumar |
17 |
Milpitas |
Saravanan |
Kandasamy |
18 |
Cupertino |
David |
Alex |
19 |
San Francisco |
|