0

I get this error

"Every derived table must have its own alias"

When I run this query

SELECT firstname, lastname, artistId
FROM  artist
WHERE artistId=(
    SELECT artistId
    FROM roles
    WHERE movieCode ='$movie[movieCode]' and  role = 'Director'
) a      
Jeshurun
  • 22,940
  • 6
  • 79
  • 92
  • This has nothing to do with PHP. it' a purely mysql error. – Marc B Feb 05 '14 at 03:28
  • T think this is related to PHP. Its. just that the OP don't include the php code he/she used. Please take note the syntax of the `$movie[movieCode]`. – Mark Feb 05 '14 at 03:32

2 Answers2

0
SELECT firstname, lastname, artistId FROM artist WHERE artistId=
  (
    SELECT artistId FROM roles WHERE movieCode ='$movie[movieCode]' AND role = 'Director' AS directorTable
  )

Every table must be named. When you create a new table with your second SELECT statement (because that is what you are doing), you need to name it with an AS clause.

Thomas
  • 871
  • 2
  • 8
  • 21
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));

This should work, every subquery must have an alias "AS".