I have a table of blog and there is filed of category,Varchar
.I store there values with a comma to separate them like 5,6,9.
When I search with IN
operator it not show result like
Table data in POST
Id post_title category status
1 Title 1 5,4,9 1
2 Title 2 6 1
3 Title 3 6,9 1
4 Title 4 5,4,8 1
5 Title 5 6,7 1
6 Title 6 1,2,3 1
7 Title 7 4,9,8 1
8 Title 8 5,4,9 1
I try both queries below
SELECT * FROM POST WHERE category IN('6', '9');
SELECT * FROM POST WHERE category IN(6, 9);
Expected result would be
Id post_title category status
1 Title 1 5,4,9 1
2 Title 2 6 1
3 Title 3 6,9 1
4 Title 5 6,7 1
5 Title 7 4,9,8 1
6 Title 8 5,4,9 1
I want to create a query to show related post of particular post category ids. If I open post and that is in multiple category. Then I want to show related post from multiples categories.
Thanks looking for best result.
If possible provide a query in PDO also