Reputation: 81
If I have a column storing a string that is a concatenation of different days, say "Monday, Wednesday, Saturday, Sunday", is there a command in SQL, which would return that string, by only searching for "Wednesday, Sunday"?
Something along the lines of the command below:
SELECT * FROM `information` WHERE Days = "Wednesday, Sunday"
Upvotes: 1
Views: 574
Reputation: 3
You could use the LIKE command
SELECT * FROM `information` WHERE Days LIKE "%Wednesday% AND Days LIKE '%Sunday%";
Upvotes: -1
Reputation: 433
You can Use Regular expressions.It supported in all commonly used DB engines.
In MySql there is RLIKE
Operator, so your query would be something like:
SELECT * FROM `information` WHERE Days RLIKE '(Wednesday|Sunday)+.*(Wednesday|Sunday)+';
Upvotes: 1
Reputation: 1056
If the list of days is a string
SELECT * FROM `information` WHERE Days LIKE '%Wednesday%' AND Days LIKE '%Sunday%'
EDIT
Changed OR
to AND
to get rows having both dates
Upvotes: 2
Reputation: 26927
Convert your source query into a like query, assuming the search string is in the right order:
SELECT *
FROM information
WHERE Days LIKE CONCAT('%', REPLACE(REPLACE('Wednesday, Saturday', ', ', '%'), ',', '%')), '%')
The expression converts
Wednesday, Saturday
to
%Wednesday%Saturday%
Upvotes: 0