this is the outer query --
Code:
SELECT t.id
, t.code
, t.uploaddt
, t.cp
, t.name
, t.date
FROM ( ... ) AS m
INNER
JOIN daTable AS t
ON t.code = m.code
AND t.date = m.max_date
this is the subquery --
Code:
SELECT code
, MAX(date) AS max_date
, COUNT(date) AS cnt
FROM daTable
GROUP
BY code
a subquery in the FROM clause of the outer query is called a derived table and you can think of it exactly like any other table
so in the outer query, if you want to show a column from the derived table, you must put that column into the SELECT clause
this is the SELECT clause of the outer table --
Code:
SELECT t.id
, t.code
, t.uploaddt
, t.cp
, t.name
, t.date
see? the count is missing
Bookmarks