I have a query like so
Select * from tableA A
LEFT JOIN
mydb.tableB B
ON A.pk = B.tableA_pk
LEFT JOIN
mydb.tableC C
ON B.tableC_pk = C.pk
WHERE C.PK IN ('325','305', '322')
ORDER BY A.pk desc;
This will return a result like so with potentially multiple rows for an entry where applicable
4, xxx, yyy, 325, 325, zzz <<<< most recent for this entry ( 'unique' key is tableC.pk, 325)
3, aaa, bbb, 325, 325, eee <<<< next most recent
3, ccc, ddd, 322, 322, fff
2, eee, fff, 305, 305, rrr
2, ggg, hhhh,322, 322, ttt
1, iii, jjj, 325, 325, uuu <<< oldest
Ideally i want the result to look like below, that is for each matching entry in the LIST ..IN ('325', '322') it should only return the most recent entry like below
4, xxx, yyy, 325, 325, zzz <<<< most recent
3, ccc, ddd, 322, 322, fff
2, eee, fff, 305, 305, rrr
To explain further..
Select * from tableA A
LEFT JOIN
mydb.tableB B
ON A.pk = B.tableA_pk
LEFT JOIN
mydb.tableC C
ON B.tableC_pk = C.pk
WHERE C.PK IN ('325')
ORDER BY A.pk desc;
I would get this
4, xxx, yyy, 325, 325, zzz <<<< most recent for this entry
3, aaa, bbb, 325, 325, eee <<<< next most recent
1, iii, jjj, 325, 325, uuu <<< oldest
But I need this:
4, xxx, yyy, 325, 325, zzz <<<< most recent for this entry ( 'unique' key is tableC.pk)
I have tried LIMIT 1 (I'm using MySQL) like below but this limits to 1 for the total request not 1 per searched entry in my query list.
Select * from tableA A
LEFT JOIN
mydb.tableB B
ON A.pk = B.tableA_pk
LEFT JOIN
mydb.tableC C
ON B.tableC_pk = C.pk
WHERE C.pk IN ('325','305', '322')
ORDER BY A.pk desc
LIMIT 1;