I have a table in a database to which I perform a general query, let's say:
select * from archivo
Now, I need the results to be sorted, first by pallet, then by street, row, floor... which turns the query into this
select * from archivo order by palet desc, calle asc, fila asc, piso asc
//(sí, los campos deben llevar esa ordenación ASC, DESC variable)
But the results are not ordered as requested, it only orders by the first of the filtered fields (pallet desc)
palet calle lado Fila piso ubicacion pegatina
------ ----- --------- ---- ---- ---------- ----------
LIBROS F IZQUIERDO 13 2 E PF1132
754 G DERECHO 12 3 D PG2123
753 G IZQUIERDO 1 3 A PG1013
752 G IZQUIERDO 8 3 C PG1083
751 F IZQUIERDO 11 3 D PF1113
750 F DERECHO 15 4 E PF2154
746 F IZQUIERDO 10 3 D PF1103
745 F IZQUIERDO 10 3 D PF1103
It must be said that all the fields, except the one for the floor, are text fields, but I understand that even though they are text, they should be ordered, right?
Your query is returning the values ordered by the first query, because each result is obtained by rows. Each row has a group of elements which cannot be separated, for example: If we create a table with people with the following data:
When making queries on this table it will not be possible to order by more than one element unless there are repeated elements, in this case if we order by "date and first and last name", the query will order all the rows by the date, either ascending or descending , after this, if there are repeated dates (1987-07-09), it will order the repeated names within those repeated dates and so on, leaving as a result:
In the case of your query, when ordering by the pallet field and there is no repeated element, the other fields in the ordering of the query are discarded.