Search code examples
sqltable-alias

Every derived table must have its own alias - even though i have alias for every table


My command worked and when I tried inserting it again, I keep getting this error: Every derived table must have its own alias..

This is my command:

SELECT s1.* 
FROM subpages AS s1 
  INNER JOIN (
    SELECT s2.* 
    FROM subsubpages AS s2
  ) ON s1.subpage_id = s2.subpage_id 
WHERE s1.page_id = 18;

I have different alias for both tables.. Any idea why I still get this error?


Solution

  • You need an alias for the subquery:

    SELECT s1.*
    FROM subpages s1 INNER JOIN
         (SELECT s2.*
          FROM subsubpages s2
         ) s2
    -------^ this one here
         ON s1.subpage_id = s2.subpage_id
    WHERE s1.page_id = 18;
    

    Note: Your subquery is totally unnecessary. I would advise you to remove it.