![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got a table with fields bookingId, quoteId, bookingDate I want to get the max(bookingDate) for the max(bookingId) for a given quoteId select bookingId, max(bookingDate) from table where quoteId = 1 group by bookingId gives me the max date for each bookingId select quoteId, max(bookingId), max(bookingDate) from table where quoteId = 1 group by quoteId gives me the max bookingId and the max date, but not the max date of the max bookingId do I need two queries to do this ? Yes. One query will be in the FROM clause of the other, joined to the table. |
#3
| |||
| |||
|
|
Roger wrote: I've got a table with fields bookingId, quoteId, bookingDate I want to get the max(bookingDate) for the max(bookingId) for a given quoteId select bookingId, max(bookingDate) from table where quoteId = 1 group by bookingId gives me the max date for each bookingId select quoteId, max(bookingId), max(bookingDate) from table where quoteId = 1 group by quoteId gives me the max bookingId and the max date, but not the max date of the max bookingId do I need two queries to do this ? Yes. One query will be in the FROM clause of the other, joined to the table. Create a saved query that gives you the max booking id for each quoteid. Then create a new query that joins the table to the saved query using quoteid and booking id-maxbookingid. |
![]() |
| Thread Tools | |
| Display Modes | |
| |