Given 3 tables with columns below…
table (columns)
A (a_pk, b_pk, other)
B (b_pk, a_pk, c_pk)
C (c_pk, b_pk, date)
(comment: pk is a primary key, date is a date)
…I’m trying to select…
A.a_pk, A.other, C.date
…with the following restrictions:
max(B.b_pk) group by B.a_pk (only select the maximum of B.b_pk for every A.a_pk)
A.other = ‘something’ (just a WHERE example)
ORDER BY C.date (order by latest dates)
Below is one attempt without success (others looked even more screwed up)
SELECT A.a_pk, A.other, C.date
FROM A, C
WHERE
A.other = 'something'
AND
A.a_pk IN
(
SELECT max(B.b_pk), B.a_pk, B.c_pk, C.date
FROM B
INNER JOINT C ON C.b_pk = B.b_pk
GROUP BY B.a_kp
)
ORDER BY C.date DESC
How should it be done?
try