I'm trying to query the iSeries DB2 v6r1m0. I usually test my SQL statements in System i Navigator before using them in ADO.Net.
I've traced my issue down to this, but I'm not sure how to fix it.
SELECT
a.id
, a.otherstuff
, MAX(a.date || ' ' || a.time) as adatetime /* I'm sure it's not this line */
, b.id
, b.city
, b.state
, MAX(b.date || ' ' || b.time) AS bdatetime
FROM
table1 a
INNER JOIN
table2 b
ON a.id = b.id
GROUP BY
a.id, a.otherstuff, b.id, b.city, b.state
What happens is that it shows all of the b.cities and b.states, even though I just want the b.city and b.state with the max value.
a.id a.otherstuff a.adatetime b.id b.city b.state b.datetime a.dup1 a.dup1 a.dup1 b.dup1 San Francisco CA 1-Jan 1:00 a.dup1 a.dup1 a.dup1 b.dup1 Sacramento CA 1-Jan 2:00 a.dup1 a.dup1 a.dup1 b.dup1 other cities WA 11-Jan 3:00 a.dup2 a.dup2 a.dup2 b.dup2 San Francisco CA 11-Jan 1:00 a.dup2 a.dup2 a.dup2 b.dup2 Sacramento CA 11-Jan 2:00 a.dup2 a.dup2 a.dup2 b.dup2 other cities WA 11-Jan 3:00
Why is this happening?
WHEREclause. - mustaccio