-1

This array was sorted ascending by time.

A    | B    | C
-----+------+--------------------
23/3 | 2001 | 2017-10-25 09:35:52
23/3 | 2002 | 2017-10-25 09:45:00
25/2 | 5001 | 2017-10-25 10:30:00
23/3 | 2003 | 2017-10-25 11:30:00
25/2 | 5002 | 2017-10-25 12:30:00

Now I want to sequence items of A, like in the table below. Using PHP, how can I do this?

A    | B    | C
-----+------+--------------------
23/3 | 2001 | 2017-10-25 09:35:52
23/3 | 2002 | 2017-10-25 09:45:00
23/3 | 2003 | 2017-10-25 11:30:00
25/2 | 5001 | 2017-10-25 10:30:00
25/2 | 5002 | 2017-10-25 12:30:00
Antti29
  • 2,815
  • 12
  • 34
  • 36
  • change query sql, to made DESC? – Álvaro Touzón Oct 26 '17 at 06:17
  • 1
    By sequence, don't you mean [sort](http://php.net/manual/fr/function.sort.php) ? – Plotisateur Oct 26 '17 at 06:19
  • What is the sorting logic you are using here? Both columns `A` and `B` are sorted in ascending order, but maybe you even have something else in mind. – Tim Biegeleisen Oct 26 '17 at 06:21
  • The sample data provided makes this question ambiguous and unclear. Please improve your question. Better still, take the time to research how to use mysql's `ORDER BY` clause via the manual or StackOverflow. All users are expected to do their research before posting a question and the question should include a coding attempt. This is surely a duplicate question. – mickmackusa Oct 26 '17 at 06:26
  • only upper tabe is ascending order but last table is not ascending order look at C. – Faysal Ahmed Raju Oct 26 '17 at 06:27
  • 1
    I don't use Laravel, but perhaps someone else will know if this is a fitting duplicate: https://stackoverflow.com/questions/17553181/laravel-4-how-to-order-by-using-eloquent-orm – mickmackusa Oct 26 '17 at 06:29
  • @mickmackusa i tried Order by, Group by but here is not the case look c last table after getting ascending data from upper table i have to sort data like 23/3 three data have to same serial. – Faysal Ahmed Raju Oct 26 '17 at 06:45

2 Answers2

0

You can use several column for sorting in your query. Here is the code :

Select * from table order by table.a, table.c 
Derta
  • 21
  • 1
0

First order the A column in ascending order and then order the C column in ascending order.

SQL Query will be like @Derta's answer.

Arabinda
  • 134
  • 1
  • 3