ü SELECT statement is used to retrieve data from table within a database.
ü The retrieved result is displayed in a table called ‘Result set’.
ü Some Columns
ü The syntax for retrieving the columns in the table
Syntax:
SELECT col1, col2, col3 FROM table_name
Here Col1, col2, col3 columns will return from table in result set.
ü All the columns
ü The syntax for retrieving all the columns in the table
Syntax:
SELECT * FROM table_name
ü DISTINCT
ü The DISTINCT keyword can be used to retrieve the data which is unique in the table.
ü The syntax for retrieving the data which is not duplicate in the table is
Syntax:
SELECT DISTINCT col1, col2, col3 FROM table_name
ü Where clause
ü WHERE clause is used to filter the result set.
ü It is used to retrieve the records on certain criteria/condition.
Syntax:
SELECT col1, col2, col3 FROM table_name WHERE col_name operator value
ü Following operator can be used in where clause
Operator
|
Description
|
=
|
Equal
|
<>
|
Not Equal
|
>
|
Greater Than
|
<
|
Less Than
|
>=
|
Greater than or Equal to
|
<=
|
Less than or Equal to
|
BETWEEN
|
Between a exclusive range
|
LIKE
|
Search for a pattern
|
IN
|
If you know the exact value you want to return for at least one of the columns.
|
Note:
· In where clause for text value use single quote (‘ ’).
ü ‘AND’ and ‘OR’ Operator is used to retrieve the records based on more than one condition.
ü AND Operator-
It is used when all the conditions, which are specified in the where clause are true.
Syntax:
ü OR Operator-
It is used when either of condition is true in where clause.
Syntax:
ü Combination of ’AND’ and ‘OR'
SELECT Statements:
Reviewed by kamal kumar das
on
January 20, 2012
Rating:
No comments: