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 –

IDNAMEAGEADDRESSSALARY
1Raj20Pune1000.00
2Saurabh20Pune6000.00
3Omkar24Mumbai4000.00
4Anand23Nagpur3000.00
5Anmol29Goa1000.00
6Poonam25Delhi9000.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 –

IDNAMEAGE
1Raj20
2Saurabh20
3Omkar24
4Anand23
5Anmol29
6Poonam25

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 –

IDNAMEAGEADDRESSSALARY
1Raj20Pune1000.00
2Saurabh20Pune6000.00
3Omkar24Mumbai4000.00
4Anand23Nagpur3000.00
5Anmol29Goa1000.00
6Poonam25Delhi9000.00