Friday, July 10, 2009

learn sql-Substring Pattern Matching in sql

Get all suppliers whose name has ‘A’ as its second character

SELECT sname
FROM s
WHERE sname LIKE '?A*‘

? – replaces a single character
* - replaces an arbitrary number of characters

Get the surname of suppliers whose name begin with vowels

SELECT sname
FROM s
WHERE sname LIKE '[a,e,i,o,u]*'

- Get names of suppliers whose name begin with letter ‘a’ to ‘p’

SELECT sname
FROM s
WHERE sname LIKE '[a-p]*'

- Get the names of suppliers who has an even number as the first character of their status

SELECT sname
FROM s
WHERE status LIKE '[2,4,6,8]*'

No comments:

Post a Comment