SQL SELECT Statement



A. SQL SELECT Statement : Fetching Records

SQL SELECT Statement is used to collect only required records out of number of records. This chapter will explain the SQL SELECT statement [Pictorial Representation].

  1. Select Statement is used to fetch required records from a database table.
  2. Select Statement returns data in the form of result table.
  3. Result table returned by Select Statement is also called as Result Sets.

B. Select : Syntax

SQL> SELECT column1, column2, columnN FROM table_name;

Here column1, column2, column3 … are the fields of a table whose values you want to fetch using select statement. If you want to fetch all the fields of a table then following SQL query syntax is used –

SQL> SELECT * FROM table_name;

C. Select Query : Example

Consider following “CUSTOMER” table –

ID NAME AGE ADDRESS SALARY
1 Raj 20 Pune 1000.00
2 Saurabh 20 Pune 6000.00
3 Omkar 24 Mumbai 4000.00
4 Anand 23 Nagpur 3000.00
5 Anmol 29 Goa 1000.00
6 Poonam 25 Delhi 9000.00

Query 1 : Selecting Some Fields

Now suppose user want only NAME and AGE of the all the customers then SQL Query will be like this –

SQL> SELECT ID,NAME,AGE FROM CUSTOMER;

and result will be like this –

ID NAME AGE
1 Raj 20
2 Saurabh 20
3 Omkar 24
4 Anand 23
5 Anmol 29
6 Poonam 25

Query 2 : Selecting All fields

If we want to get all the records then following query is used –

SQL> SELECT * FROM CUSTOMER;

Output of the query is as follow –

ID NAME AGE ADDRESS SALARY
1 Raj 20 Pune 1000.00
2 Saurabh 20 Pune 6000.00
3 Omkar 24 Mumbai 4000.00
4 Anand 23 Nagpur 3000.00
5 Anmol 29 Goa 1000.00
6 Poonam 25 Delhi 9000.00