I am working on a project that was started with someone else. In the db instead for using a separate table the developer had opted for saving the 1 to many
relationships on a single table with comma separated tables. The table structure is like this
CREATE TABLE pages(
pageid INT(6) AUTO_INCREMENT PRIMARY KEY,
newsid INT(6),
pages VARCHAR(30)
);
How can I search for a value 1
from the column pages
. I have identified a few conditions that may appear, but was not been able to create a solution for it.
If I am searching for 1
the following patterns should be handles
1, match
11 shouldn't match
11, shouldn't match
,1, match
,1 match
1 match
21 shouldn't match
21, shouldn't match
I have been thinking about this for sometime, but no solution came up. I don't think normal %LIKE%
can be used here
Sample sql on sqlfiddle
Also I need to search multiple values too like 1
, 7
and 3