English | 正體中文 | 简体中文

SQL like,not like


范例资料表 : Orders (以下范例皆用此表当作资料来源)
OrderNo CustomerName Shipped SalePrice Quantity
20101213095 John True 13500 10
20100620135 Jimmy False 25096 22
20100620392 Vincent False 7200 5
20100530006 Tyler True 92500 50


Example
选择出完全符合或是符合万用字元搜寻的资料列

Sytax : SELECT * FROM table_name WHERE search_column_name LIKE search_condition
SQL
SELECT * FROM Orders WHERE CustomerName LIKE 'John'

会输出结果
OrderNo CustomerName Shipped SalePrice Quantity
20101213095 John True 13500 10


Example
选择出OrderNo栏位里有 '0620' 字串的资料列

Sytax : SELECT * FROM table_name WHERE search_column_name LIKE '%0620%'
SQL
SELECT * FROM Orders WHERE OrderNo LIKE '%0620%'

会输出结果
OrderNo CustomerName Shipped SalePrice Quantity
20100620135 Jimmy False 25096 22
20100620392 Vincent False 7200 5


Example
不符合(NOT LIKE), 选择出不符合搜寻值的资料列

Sytax : SELECT * FROM table_name WHERE search_column_name NOT LIKE search_condition
SQL
SELECT * FROM Orders WHERE OrderNo NOT LIKE '201012%'

会输出结果
OrderNo CustomerName Shipped SalePrice Quantity
20100620135 Jimmy False 25096 22
20100620392 Vincent False 7200 5
20100530006 Tyler True 92500 50

© 2012 PureExample.com contact