Tuesday, January 13, 2009

Using Comparison Conditions in SQL

Operators
  • = (Equal to)
  • > (Greater than)
  • >= (Greater than or equal to)
  • <> Not equal to
  • BETWEEN...AND... Between two values (inclusive)
  • IN(set) (Match any of a list of values)
  • LIKE (Match a character pattern)
  • IS NULL (Is a null value)

SQL> select tname from test where salary<=2000;
TNAME
--------------------
vinay
kumar

SQL> select tname from test where salary between 500 and 2000;

TNAME
--------------------
vinay
kumar

SQL> select tname,salary from test where tno in (1,3);

TNAME SALARY
-------------------- ----------
vinay 1000
kasarapu 5000

SQL> select tname,salary from test where tname like 'k%';

TNAME SALARY
-------------------- ----------
kumar 2000
kasarapu 5000

SQL> select tname,salary from test where tname like '_u%';

TNAME SALARY
-------------------- ----------
kumar 2000

% denotes zero or many characters.
_ denotes one character.


SQL> select tno from test where tno is null;

no rows selected

No comments:

Post a Comment