Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL innerjoin在数组_字段上_Mysql_Join - Fatal编程技术网

MySQL innerjoin在数组_字段上

MySQL innerjoin在数组_字段上,mysql,join,Mysql,Join,我有两张桌子 [series] -------------- ID | ART -------------- 1 | sculptor 2 | painter 3 | writer -------------- [artists] -------------- NAME | ART_IDs -------------- john | 1 jack | 1,2 jill | 2,1 jeff | 3,1 我想这样加入: SELECT se.art, ar.name as a

我有两张桌子

[series]
--------------
ID | ART
--------------
1  | sculptor      
2  | painter
3  | writer
--------------


[artists]
--------------
NAME | ART_IDs
--------------
john | 1
jack | 1,2
jill | 2,1
jeff | 3,1
我想这样加入:

SELECT se.art, ar.name as artist
FROM series AS se
INNER JOIN artists AS ar ON (se.id IN (ar.art_ids))
我得到的只是第一个值:

[result]
-------------------
ART      | ARTISTS
-------------------
sculptor | john
sculptor | jack
painter  | jill
writer   | jeff
而不是:

[result]
-------------------
ART      | ARTISTS
-------------------
sculptor | john
sculptor | jack
sculptor | jill
sculptor | jeff
painter  | jack
painter  | jill
writer   | jeff

通常,我会使用第三个带有链接pe.idse.id的表来执行此操作。但是,在我的框架中维护另一个表是相当复杂的。

如上所述,最好的选择是修复您的表结构,最好在有机会的时候立即修复。随着数据的增长,它将开始引起很多麻烦。但是,如果您知道自己在做什么,我认为这将在短期内满足您的需求:

SELECT se.art, ar.name as artist
FROM series AS se
JOIN artists AS ar ON FIND_IN_SET(se.id , ar.art_ids) > 0

我建议您对该领域进行规范化,这是您的结果的原因,并且会不断地给您带来更多的麻烦,而不是在该领域中不采用良好的设计DB@Andrew我看到了,通常我会的。非常感谢。由于这两个表不会有太大的变化,而且用户通过标准Joomla表单(在这里我可以简单地使用多选列表创建字段)来更新I artists,所以我不想对其进行更改。谢谢。我确实搜索了很多,但现在当我搜索FIND_IN_SET时,有几个类似的问题。。。。我道歉。对于任何尝试此操作的人来说,有一件事:字符串中不能有空格。由于mysql不能使用索引,所以数据量很大,速度会变慢。