Thursday, September 17, 2009

Using Comparison Conditions in SQL Statement

Comparison Conditions :



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

Using Comparison Conditions :
  • select*from emp where sal<3000;
Using the BETWEEN Condition :
  • select*from emp where sal between 1 and 2999;
Using the IN Condition :
  • Use the IN membership condition to test for values in a list:
  • select*from emp where mgr in(7902,7698);
Using the LIKE Condition :
  • Use the LIKE condition to perform wildcard searches of valid search string values
  • Search conditions can contain either literal characters or numbers
    • % denotes zero or many characters
    • _ denotes one character
  • SELECT * FROM emp WHERE ename LIKE 'S%' ;
Using the NULL Conditions :
  • Test for nulls with the IS NULL operator
  • SELECT ename, mgr FROM emp WHERE mgr IS NULL ;

Wednesday, September 16, 2009

Limit the rows that are retrieved by a query

Limiting Rows Using a Selection :
  • Restrict the rows that are returned by using the WHERE clause
  • The WHERE clause follows the FROM clause
  • SELECT *|{[DISTINCT] column|expression [alias],...} FROM table [WHERE condition(s)];
  • eg : select*from emp where deptno=10;
Character Strings and Dates :
  • Character strings and date values are enclosed by single quotation marks
  • Character values are case-sensitive, and date values are format-sensitive
  • eg : select*from emp where ename='CLARK';

Followers