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

39 Views Asked by At

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?

2

There are 2 best solutions below

0
Gordon Linoff On BEST ANSWER

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.

1
Fahmi On

You can try below - need to add alias for you subquery

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;

It seems to me you don't need even any derived table - just simply you can follow below -

SELECT s1.* FROM subpages AS s1 join subsubpages s2 
ON s1.subpage_id = s2.subpage_id WHERE s1.page_id = 18