Dave, you could just use a LIKE statement

SELECT *
FROM table
WHERE mystring LIKE "%,2,%"

Of course if it is at the beginning or end, or the only item, it may
look like '2' '2,' or ',2' and not ',2,' so this would work in all
cases I think:

WHERE (mystring LIKE "%,2,%" OR mystring LIKE "2,%" OR mystring LIKE
"%,2" OR mystring = "2")

Performance will be terrible if this grows much but for a trivial
implementation it should work.

Dan



On 11/4/06, David T. Ashley <[EMAIL PROTECTED]> wrote:
Hi,

I'm a little bit lost on MySQL statements.

I am implementing a many:many relationship using a string (wrong way, I
know, but I'm trying to keep the design simple and this is a trivial
application).

In a VARCHAR field, I will store a comma-delimited set of integers
corresponding to the indices in another table.  It might look like:

,1,2,9,

to specify a link to records 1, 2, and 9.

I'm not sure how to find, for example, all records where the text of a given
field contains ",2,".

I'm not interested in an efficient search, just a search.  I know it will be
O(N) unless indexing of some kind is used.

My explanation above might be confusing, so let me give an example that will
give the same answer ...

Suppose I'm interested in searching a table for all records with last names
that contain "sh".  How would I do that?

(Different problem, same answer.)

Thanks, Dave.



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to