Powered By Blogger

Thursday, June 19, 2014

some useful queries in SQL

Query to list all employees except who are joined on 11- Sep-2001, 31-Mar-2001 and 30-Jan-2001(It also compares time).

   SELECT * FROM EMP WHERE HIREDATE NOT IN ( DATE('09-11-2001'),
                                          DATE('03-31-2001'),DATE('01-30-2001') )

 To list all the employees whose names are having ‘O’ as second character
       SELECT * FROM EMP WHERE ENAME LIKE '_O%'

 To list all the employees whose names are having ‘R’ as last character
       SELECT * FROM EMP WHERE ENAME LIKE '%R'

 To list all the employees whose names are having just 5 characters as length.
      SELECT * FROM EMP WHERE LENGTH(ENAME) = 5      

 To list all the employees whose names are starting with  ‘R’ and ending with ‘O’
   SELECT * FROM EMP WHERE ENAME LIKE 'R%O'

No comments:

Post a Comment