考虑下表:选择所有多对多的关系
author
--------------
id int(11)
name varchar
author_type
---------------
id int(11)
type varchar
author_has_type
---------------
author_id int(11)
author_type_id int(11)
我想写一个查询,执行以下操作;
给出一个作家类型就会显示我正在努力做到这一点的以下
author.name types
-The authors name- -All types of the author-
现在查询是
Select author.name, GROUP_CONCAT(author_type.type) as types
from author
left join author_has_type on author.id = author_has_type.author_id
left join author_type on author_has_type.author_type_id = author_type.id
where author_type.type = "EXAMPLE TYPE"
但是当我这样做,它只是只返回给定的类型在group_concat中。我明白为什么会发生这种情况,但是有没有办法让每一个作者都可以使用?
是的,但只会得到所有的作者和他们的所有类型。我正在寻找所有作者及其所有类型,并在where子句中使用指定的类型。 – user2827048
@ user2827048。 。 。你的问题澄清了这个问题。看我的编辑。 –