Question: Why this query wont work? Is it beacause combinaton of order by and group by? 

One table is with adverts, other with subscriptions, third is with services, and fourth is many to many relation between services and locations (location is position where advert should be shown). 

What i want is to order adverts stored in adverts table having location 2 first, then those who don't have location defined and then with location 1 (this order is generated programmicaly)

adverts table:  

**id**, name, subscription\_id

subscriptions table:  

**subscription\_id**, service\_id, date, paid etc...

service\_locations table:  

**service\_id**, **location\_id**

as you can se there is fourth table in this case, but it is unimportant

The query:

```
select adverts.id, GROUP_CONCAT(service_locations.location_id) AS locations from adverts 
    left join subscriptions 
        on adverts.subscription_id = subscriptions.id
    left join service_locations 
        on service_locations.service_id = subscriptions.service_id
    group by adverts.id
    order by case service_locations.location_id 
        when 2 then 1 
        when 1 then 3 
        else 2 
    end

```

Expected results:

```
+----+-----------+
| id | locations |
+----+-----------+
|  1 | 2         |
|  3 | 1,2       |
|  2 | null      |
+----+-----------+

```

What i actually get (the third in row has location 2 but it is placed after null):

```
+----+-----------+
| id | locations |
+----+-----------+
|  1 | 2         |
|  2 | null      |
|  3 | 1,2       |
+----+-----------+

```

Answer: 
You can use [Pandas](http://pandas.pydata.org/pandas-docs/stable/) for that.

```
import pandas as pd
print pd.DataFrame(yourArray)

```
**Note**: 
Konstantinos proposal holds only for 1-D and 2-D arrays!

You can use `numpy.array2string()`:

```
from pprint import pprint
import numpy as np

array = np.array([[1,2,3], [4,5,6]])
print(np.array2string(array).replace('[[',' [').replace(']]',']'))

```

Output:

```
 [1 2 3]
 [4 5 6]

```

**See also:** [Printing Lists as Tabular Data](https://stackoverflow.com/questions/9535954/printing-lists-as-tabular-data)