Forum Moderators: coopster

Message Too Old, No Replies

Searching from Array

         

Gian04

9:57 am on Nov 10, 2008 (gmt 0)

10+ Year Member



I have a table with 5 records

mon, tue, thu, fri, sat, sun
mon, web, fri
tue, web, sat, sun
mon, thu, sun
thu, fri, sat, sun

Now how can I create a query that will search for rows with "thu"?

solow

10:03 am on Nov 10, 2008 (gmt 0)

10+ Year Member



What do you mean? be more specific....

Sekka

10:03 am on Nov 10, 2008 (gmt 0)

10+ Year Member



Try,

SELECT * FROM myTable WHERE myField LIKE "%thu%"

Replacing myTable with your table name and myField with your field name.

Gian04

11:37 am on Nov 10, 2008 (gmt 0)

10+ Year Member



"Like" will definitely work, but what is I have a record
abcmon, tueytr, rthuxx, satzzz

Then it will find a row, but it should not because I only want to search for a record that contains "thu"

[edited by: Gian04 at 11:39 am (utc) on Nov. 10, 2008]

jatar_k

2:09 pm on Nov 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



then remove the %

SELECT * FROM myTable WHERE myField='thu'

Gian04

2:38 pm on Nov 10, 2008 (gmt 0)

10+ Year Member



What?

Then how it can find my record. Please see my 1st post jatar_k

jatar_k

3:39 pm on Nov 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



first you have to identify the pattern

what exactly do you want and not want, explain the pattern, maybe what you really want is '%thu,%' not '%thu%'

secondly, using like searches with %'s on a text field is slow

Anyango

6:31 am on Nov 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So Simple

SELECT * FROM myTable WHERE myField LIKE 'thu, %' OR myField LIKE '% thu,%' OR myField LIKE '%, thu'

it will only return records that either contain

1) thu, **********
2) **, thu, **
3) ***, thu

and will not return any row that says "rthuxx"

[edited by: Anyango at 6:36 am (utc) on Nov. 11, 2008]