Table ALIAS of INNER JOINs ?!?!

S

snufa snafu

hey volks.


i'm struggeling really hard on this one! basically i just want to get
the groupwise maximum (in this case the latest entries /
ranks.checked_at). i try something like this:

SELECT urls.url, keywords.keyword, ranks.rank
FROM (urls INNER JOIN keywords ON urls.ID = keywords.url_id) INNER
JOIN ranks ON keywords.ID = ranks.keyword_id AS xxx,
(SELECT keywords.keyword, MAX(ranks.checked_at) AS latest FROM
keywords INNER JOIN ranks ON keywords.ID = ranks.keyword_id GROUP BY
keywords.keyword) AS yyy
WHERE yyy.keyword = xxx.keyword
AND xxx.created_at = yyy.latest;

but it seems as if the 'AS xxx' statement isn't valid after INNER
JOINs of tables...


please help me, i'm really lost!

thanks so much,
-bernd
 
K

KARL DEWEY

I am in the learning stage for subqueries but I see several errors.

Your FROM has a comma -- xxx, (SELECT -- and that is not allowed.

Your AS xxx is misplaced. Needs to be -- INNER JOIN ranks AS xxx ON
keywords.ID = xxx.keyword_id

I can not figure what you want from the subquery. You have it in the FROM
clause but also have output of subquery 'AS yyy' appear as if you want an
output field.

Explain a little more what you are trying to do with the subquery.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top