Wednesday 25 November 2015

SELECT command in SQL

SELECT command in SQL is used for retrieving the data either from a table or tables.

Syntax:
SELECT <columnlist> from <table name> [<condition>]

Example:
1.       SELECT * from Bank
Above query retrieves all the records (all rows and columns) from table Bank

2.       SELECT * from Bank where Custid=105
Above query retrieves the record of customer having customer id =105

3.       SELECT * from Bank where Cname= NULL
This is incorrect SQL statement as NULL is not comparable because NULL is infinite or unknown value.

4.       SELECT * from Bank where Cname is NULL
We can make use of NULL value in SQL as mentioned in above query.

Query 3 will not retrieve any data because NULL value cannot be compared with another NULL value. In terms of a database, NULL value is treated as infinite or unknown value as two infinite or unknown values cannot be compared with each other. Two NULL’s also cannot be compared with each other.

When you want to perform a comparison on NULL values using operators like =,! =, <,<=,>,=> is not possible. You can use only is ‘IS NULL’ or ‘IS NOT NULL’


No comments:

Post a Comment