Answer the question
In order to leave comments, you need to log in
How to use ORDER BY correctly?
Hello!
There are two tables:
When selecting from them, it is necessary to sort by status (status), by date of modification (o.date_modified) and by what the user additionally selects (for example, by customer).
Used the following query:
SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM oc_order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '1') AS status, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `oc_order` o WHERE o.order_status_id > '0' ORDER BY status ASC, o.date_modified ASC, customer
ASC I get sorted by status and date, but not by customer
Answer the question
In order to leave comments, you need to log in
ORDER BY status ASC, o.date_modified ASC, customer ASC - such a record filters by status, if there are identical statuses, then they will be sorted by date, and if the dates are the same, then they will be sorted by customer. Sort first by customer, then by date_modified
o.date_modified - in seconds, it will sort by customer only if there are multiple records with the same date_modified
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question