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
  • 11
  • 3
  • Possible duplicate of [PHP MySQL Order by Two Columns](https://stackoverflow.com/questions/514943/php-mysql-order-by-two-columns) – Eaten by a Grue Nov 18 '18 at 04:38

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,198,228
  • 53
  • 572
  • 709