gpt4 book ai didi

mysql - Inner Join 获取所有属性

转载 作者:行者123 更新时间:2023-11-29 01:40:49 25 4
gpt4 key购买 nike

我有 2 个表:

albums (idalbum, idauthor, idcompositor, idfeat)
people (id, firstname, last name)

我当前的查询:

SELECT * FROM albums where idalbum=:id
INNER JOIN people ON albums.idauthor = people.id
INNER JOIN people ON albums.idcompositor = people.id
INNER JOIN people ON albums.idfeat = people.id

我想对我的查询做什么:

[Album], [Author[First Name, Last Name]], [Compositor[First Name, Last Name]], [Feat[First Name, Last Name]]

我的问题:
我有一个错误:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;

最佳答案

您需要更正您的查询 where 子句应该在您的连接语句之后使用,而且您没有使用正确的表名,根据问题中显示的结构,您可以将查询写为

SELECT * FROM albums  a
INNER JOIN people p ON a.idauthor = p.id
INNER JOIN people p1 ON a.idcompositor = p1.id
INNER JOIN people p2 ON a.idfeat = p2.id
where a.idalbum=:id

关于mysql - Inner Join 获取所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23424595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com