I have two tables Posts, categories
. Here in the posts table I stored the category values as comma separated string like this 5,8,23,7
. While displaying the posts, I just want to show the post categories as comma separated like this Flower, Birds, Animals
. So I tried some queries nothing helped me to get it. The Posts Table Example.
ID Post title categories
3 Example Post 5,7,23,8
And the Categories Table will be like this
ID name
5 Flowers
7 Animals
8 Birds
23 Naturals
And I want result like this
ID Post Tile Category
3 Example Post Flowers, Animals, Birds
For that I tried this query but didn't help me to get it .
SELECT post.ID, post.Post_title, (SELECT cat.name FROM Categories as cat WHERE cat.ID IN (post.category)) AS Categories FROM Posts as post
And it returns only one category, it retrieves the first category name only.