SELECT MONTH(sessionStart) AS Expr1, YEAR(sessionStart) AS Expr2
FROM tblStatSessions
WHERE (projectID = 187)
GROUP BY sessionStart
This returns:
11 | 2010
11 | 2010
11 | 2010
12 | 2010
12 | 2010
But I need it to only return each instance once, IE:
11 | 2010
12 | 2010
If that makes sense!
The following should be what you want:
SELECT MONTH(sessionStart) AS Expr1, YEAR(sessionStart) AS Expr2
FROM tblStatSessions
WHERE (projectID = 187)
GROUP BY MONTH(sessionStart), YEAR(sessionStart)
in general you need to group by
every non-aggregate column that you are selecting. Some DBMSs, such as Oracle, enforce this, i.e. not doing so results in an error rather than 'strange' query execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With