我收到此错误
“每个派生表都必须有自己的别名”
当我运行此查询时
SELECT firstname, lastname, artistId
FROM artist
WHERE artistId=(
SELECT artistId
FROM roles
WHERE movieCode ='$movie[movieCode]' and role = 'Director'
) a
答案 0 :(得分:0)
SELECT firstname, lastname, artistId FROM artist WHERE artistId=
(
SELECT artistId FROM roles WHERE movieCode ='$movie[movieCode]' AND role = 'Director' AS directorTable
)
每个表都必须命名。使用第二个SELECT语句创建新表时(因为这就是您正在执行的操作),您需要使用AS子句对其进行命名。
答案 1 :(得分:0)
$row1=mysqli_query($conn,"
SELECT firstname, lastname, artistId
FROM artist WHERE
artistId=(SELECT artistId FROM roles WHERE movieCode ='$movie[movieCode]' and role = 'Director') AS table_alias ")or die(mysqli_error($conn));
这应该有效,每个子查询必须有一个别名“AS”。