SQL LIKE, NOT LIKE .

Selection with LIKE, NOT LIKE

LIKE is used in a WHERE statement to find specified pattern in a column. Rows that satisfy the pattern is selected.
LIKE Example:
MySQL, Oracle, SQL server, PostgreSQL:
select customer_id, telephone_type, Telephone_number
   from telephones
   where telephone_number  like '_3%-54' ;
The character, %(percent), has the meaning, any character type and any number of characters
while _(underline) has the meaning any character type at the position it appears!
So this example will list rows with some columns from telephones table where the Telephone_number has the second character as 3 and ends with the three characters -54.
The result should be:
customer_id telephone_type telephone_number
10003 Cell (371) 153-54
10003 Work (371) 143-54
NOT LIKE Example:
MySQL, Oracle, SQL server, PostgreSQL:
select customer_id, telephone_type, Telephone_number
   from telephones
   where telephone_number  not like '-54' and telephone_type='Home' ;
This example will list rows with some columns from telephones table where the Telephone_number not ends with the three characters -54 and telephone is 'Home' type.
The result should be:
customer_id telephone_type telephone_number
10001 Home (978) 667-94
10002 Home (679) 234-94
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.