简体   繁体   中英

Select Multi rows from table B according to array value in table A

I have two tables (A, B), B table has a column Fruit which stores id values of table A rows as array, how can I output the title of each id in table B, like that: 输出表B中每个ID的标题,如下所示:

Table B :

id    title
1    Apple
2    Orange

Table A :
id   Fruit
1    1,2

result:

A.id  A.Fruit
1      Apple,Orange
SELECT a.id, GROUP_CONCAT(b.title)
FROm tableA a
LEFT JOIN tableB b
ON FIND_IN_SET(b.id , a.Fruit)
GROUP BY a.id

SELECT Fruit FROM Table B WHERE Fruit IN (SELECT Fruit FROM Table A); I don't know if this will work for you but I hope it helps. You will probably need to use Subqueries .

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