1

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?

Ilona
  • 101
  • 9

2 Answers2

2

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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

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
Fahmi
  • 37,315
  • 5
  • 22
  • 31
  • 1
    Works, thankyou :) Too bad I can't accept 2 answers, so I chose to accept the one that came first, sorry for that. – Ilona Oct 03 '19 at 11:10