简体   繁体   English

根据表A中的数组值从表B中选择多行

[英]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 IN ONE SELECT STATEMENT the title of each id in table B, like that: 我有两个表(A,B),B表具有一列Fruit ,该列将表A行的ID值存储为数组,如何在一个选择语句中输出表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 . 您可能需要使用Subqueries

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何只从表中选择行一个clumns值超过MySQL中的b表计数值 - How to select only rows from a table one clumns value is more than b table count value in MySQL 选择表A中与表B的所有项目结合的行 - Select rows in table A that junction to all of a set of items from table B MySQL select 来自一个表的行,第二个表中有多行,并在所选行中获取多行数组 - MySQL select row from one table with multiple rows in a second table and get array of multi row in selected row 如何从表A中选择与表B不匹配的行(使用时间范围,基于表B) - How to SELECT rows from table A that do not match with table B (using time range, based from table B) 从MySQL表中选择值是数组的行? - Select rows from a MySQL table where value is an array? 如何使用数组中的值通过2行比较来选择mysql中的表? - How to select table in mysql with comparison by 2 rows using value from array? 如果表 B 小于表 B 列 col1 比较表 A,则从表 B 中选择行 - Select rows from table B if it is less than Table B Column col1 comparing Table A 从多表SELECT的特定表中删除行 - Delete Rows from pecific Table on Multi-table SELECT 根据另一个表中ID的代表次数从一个表中选择行 - Select rows from one table according to the number of reps of the id in another MYSQL-选择不在表B中的表A行,除了行在表C中 - MYSQL - select TABLE A rows that are not in Table B except the rows are in TABLE C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM