简体   繁体   中英

joining of two mysql table with PHP in single query

I have the following two tables. I want to join them in a single query.I am able to do it with inner join if the Blog_Category_Id in Blog table is a single value. But when it comes as a multiple value how can i do it?

First Table

Second Table

Below is the result table which i want to show...

Result Table

SELECT b.* ,GROUP_CONCAT(bc.blog_category ORDER BY bc.id) blog_category
FROM blog b 
INNER JOIN blog_category bc ON FIND_IN_SET(bc.id, b.blog_category_id)
GROUP BY b.id

You can you FIND_IN_SET in INNER JOIN Check here You may got answer

MySQL Join two tables with comma separated values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM