Обсуждение: Sql query with partial matching
How would I write an sql statement which would select all the records from a table where some string field contains some substring? Example: find all the records where f1 contains the world "cool." Thanks, -- ---------------------------------------------------------------- Travis Bauer | CS Grad Student | IU |www.cs.indiana.edu/~trbauer ----------------------------------------------------------------
On Thu, 7 Dec 2000, Travis Bauer wrote: > How would I write an sql statement which would select all the > records from a table where some string field contains > some substring? Example: find all the records where f1 contains > the world "cool." SELECT * FROM mytable WHERE f1 LIKE '%cool%'; or use a regular expression: SELECT * FROM mytable WHERE f1 ~* 'cool'; http://www.chapelperilous.net/~bmccoy/ --------------------------------------------------------------------------- "Pascal is Pascal is Pascal is dog meat." -- M. Devine and P. Larson, Computer Science 340
At 14:58 07/12/00 -0500, Travis Bauer wrote: >How would I write an sql statement which would select all the >records from a table where some string field contains >some substring? Example: find all the records where f1 contains >the world "cool." select * from table where f1 ~ 'cool'; or case insensitive select * from table where f1 ~* 'cool'; Steve -- thorNET - Internet Consultancy, Services & Training Phone: 01454 854413 Fax: 01454 854412 http://www.thornet.co.uk