Home • About • FAQs • News • Random Expert Selector • Random Question Selector • Contact Us • 

Top Level >

Internet Technology

Mr Satheeshkumar Mv India
In a mysql database one of the cells in the table contain a value like "potato, potatoes, app,apple"

I want to select from database where the coloumn contain potatoes. For this I use a wild card %,potatoes,%.....But while checking for potato. I can not do it because there is no coma before potato. Also I can not use a wildcard like the one used above. The solution I found is to add a coma at the begenning and at the end...My question is is there any method to select it without adding unwanted comas in database? ..Or ..can I set a condition that if data=",".$data."," and then selecting. Is any such conditional queries possible with mysql?

Discuss this question
Discuss Answer

Do a search using the like sql and the search will find everything that contains that word regardless of the comma: here is an example

SELECT fieldname1,fieldname2
FROM TableName
Where fieldname1 like '%potatoes%'

Mr Gavin Holmes
(Expert Rating 7)
Discuss Answer

Gavin is correct, the '%' marker means "anything, or nothing", so having a % directly before the word you're searching for will include matches that have a comma before the word, or not.

Fair warning though, the 'like' operator is much a much slower search, because it is also case-insensitive... it will also find matches for POTATOES, PoTaToEs, potatoes, potatoeS, etc.

(Expert Rating 1565)
   Member has an expert rating of 1000+
 Top of Page Terms and Conditions Privacy Disclaimer

© Simply Explained