Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick SQL question

Status
Not open for further replies.

azzazzello

Technical User
Jan 25, 2005
297
US
Hi there,

I have an application which returns a particular variable as a comma-separated list (e.g. 5,blah,4,78,gamma). I need to select all rows where a MySQL variable is equal to any one of those entries. If I could quote the list in the application, this would be easy -

SELECT * from mytable where myfield IN ('5','blah'...)

but the application does not allow me to quote :( all it allows me to do is use it in a query as a block. Is there any trick I can use to select rows that match entries in this blob of a variable?
 
You could try:
[tt]
SELECT *
FROM mytable
WHERE
CONCAT(',','5,blah,4,78,gamma',',')
LIKE CONCAT('%,',myfield,',%')
[/tt]
It will be slow though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top