R
R
Roman Kuzmenko2015-12-01 12:34:07
PHP
Roman Kuzmenko, 2015-12-01 12:34:07

How to use ORDER BY correctly?

Hello!
There are two tables:
34c5531e50944a17b572f74aa3dd12c0.png8c0700d120a44ff3b82e608b4158581a.png
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

3 answer(s)
A
Aleksey Ratnikov, 2015-12-01
@devrvk

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

A
Andrey Burov, 2015-12-01
@BuriK666

o.date_modified - in seconds, it will sort by customer only if there are multiple records with the same date_modified

R
romy4, 2015-12-01
@romy4

use DATE(o.date_modified) to have it sorted by day (this will exclude hours and minutes)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question