Monday 15 February 2010

Search Condition ( Interbase Tutorial # 9 )

NOT

You can use NOT if you want to retrieve data which value is not equal to the condition. The syntax is :

    SELECT column FROM table
    WHERE NOT column = value

The other way to get the same data is :

    SELECT column FROM table
    WHERE column != value

Example 1 : we want to retrieve all data except data which age is above or equal to 30.

    select * from employee where not age<30

the statement above will have the same output with this statement below :

    select * from employee where age>=30

Example 2 : we want to retrieve data except the data which name is Archimedes.

    select * from employee where name!=’Archimedes’

LIKE

LIKE is used for retrieving data which has a particular matches with the pattern condition you give. The syntax is :

    SELECT column FROM table
    WHERE column LIKE ‘%pattern’

Example 3 : we want to retrieve data which name is ended with a particular pattern ‘ton’ 

    select * from employee where name like ‘%ton’

Example 4 : we want to retrieve data which name has a particular pattern ‘chi’ in the middle.

    select * from employee where name like ‘%chi%’
 
Example 5 : we want to retrieve data which name is started with a particular pattern ‘Ge’ 

    select * from employee where name like ‘Ge%’

STARTING WITH

You can use STARTING WITH if you want to retrieve data which column’s value started with a pattern. The syntax is :

    SELECT column FROM table
    WHERE column STARTING WITH pattern

Example 6 : we want to retrieve data which name is started with ‘Bla’

    select * from employee where name STARTING WITH ‘Bla’

it will have same output with the statement below :

    select * from employee where name like ‘Bla%’

CONTAINING

You can use CONTAINING to retrieve data which contain a value. The syntax is :

    SELECT column FROM table
    WHERE column CONTAINING value

Example 7 : we want to retrieve data which name contains ‘s’ letter

    select * from employee where name containing ‘s’


BETWEEN and IN

BETWEEN is for retrieving data within a range value. The syntax is :

    SELECT column FROM table
    WHERE column BETWEEN value1 AND value2

The statement below will get the data which name is started with a letter between C and J.

    select * from employee where name between ‘C’ and ‘J’

IN is for retrieving data with several values to be compared. The syntax is :

    SELECT column FROM table
    WHERE column IN (value1, value2, value3…….)

The statement below will get the data which age is 25, 27 or 32

    select * from employee where age in (‘25’,’27’,’32’)

Go to Previous Tutorial or Next Tutorial

0 comments:

Post a Comment

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.