0

I know how to search the LATEST date and the MOST value specifically:

Most Quantity Used:

SELECT * FROM tour_packages
WHERE active = 1
ORDER BY quantity_used DESC

Latest Date:

SELECT * FROM tour_packages  
WHERE active = 1 
ORDER BY start_date DESC

But how can I do both, by able to search the LATEST date WITH the MOST value in quantity_used? Is this practice even possible?

EDITED: I think my question is not clear enough.

I intend to find the data with the LATEST date first, then from that result FIND the highest VALUE from quantity_used.

YGOPRO
  • 29
  • 5

1 Answers1

2

I think you just want two order by keys:

SELECT tp.*
FROM tour_packages tp
WHERE tp.active = 1 
ORDER BY tp.start_date DESC, tp.quantity_used DESC;

This returns the rows ordered by date and within each date, the ones with the largest quantity go first.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786