I’ve got some problem. I have 3 tables Product, Version, Date.
Dependencies:
version.ProductId = Product.Id(there are >=1 versions of one product)Date.VersionId = Version.ID(one to one)
I want to get pairs product – version where Date of Version is Max (for each product)
Something like:
Product 1 - 1.0
Product 2 - 0.9 etc
I tried with the following query :
SELECT
productName, versionName
FROM
(SELECT
p.Name AS productName, v.Name AS versionName, MAX(d.Date) AS ddate
FROM
Product AS p
INNER JOIN
Version AS v ON v.ProductId = p.Id
INNER JOIN
Date AS d ON d.VersionId = v.Id
WHERE
(d.Date < { fn CURDATE() })
GROUP BY p.Name) AS prd
But I get an error:
Column Version.Name is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
How to handle that ?
You need to include v.Name in the group by clause
Edit.