querying multiple values in one cell
Is it possible to do the following:
If I have a column called 'fruit' in a table called 'mytable' which contains cells such as:
apple orange orange
...can I query this so that
SELECT * FROM mytable WHERE fruit='apple' && 'apple'
would return nothing, since there are no cells with the word 'apple' twice,
SELECT * FROM mytable WHERE fruit='orange' && 'orange'
would return the third cell, because 'orange' DOES appear twice?
If this question doesn't make sense to you, you're probably not best-suited to respond :-)
With MySQL, you can query for a match on two separate words like this
but if you search for '%apple%' AND '%apple%', SQL doesn't realize you are looking for two instances of the same word. To do that, you would need to format your query like this
WHERE `fruit` LIKE '%apple%' AND `fruit` LIKE '%orange%'
Hope that helps.
WHERE `name` LIKE '%apple%apple%'
I forgot to change my column name in that last snippet- sorry. It would be this:
WHERE `fruit` LIKE '%apple%apple%'
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)