SQL Retrieve Data

Select statement is popular statement in SQL language to retrieve data from database. Basic statement consist of keyword “Select” and “From”. To tell database which table you want to query you can use “From” keyword. To identify what columns use “Select” keyword.

Lets take a look sample data below :

Table : countytbl

id county zip
1 Morehouse 71220
2 Tangipahoa 70422
3 Iberia 70544
4 Saint Landry 70570
5 Saint Charles 70087
Select county From countytbl

Output:

Morehouse
Tangipahoa
Iberia
Saint Landry
Saint Charles

Retrieve Data From Multiple Columns

To retrieve multiple columns you can use format “Select column1, column2, column3 from table”.

Select county, zip From countytbl

Output:

Morehouse     71220
Tangipahoa    70422
Iberia        70544
Saint Landry  70570
Saint Charles 70087

Limit The Result

If your database is to large it is not recommended to query all records. SQL use keyword “LIMIT” to deal with this situation. On Oracle database you can use keyword “WHERE ROWNUM <= number of rows”.

Select county, zip From countytbl LIMIT 3

Output:

Morehouse     71220
Tangipahoa    70422
Iberia        70544