Imagine a table like this over 100 fields and I shrink it

```
     the_id | company        |   abcd     | master_id
   ---------+----------------+------------+------------------
        500 | M-803          |            |                0
        501 | M-803          |            |                0
        502 | M-803          |            |                0
        503 | M-803          |            |                0
        504 | M-803          |            |                0
        507 | M-803          | 45 KK 526  |              505
        506 | M-803          | ARC0032    |              505
        505 | M-803          | 355 KKK 65 |                0
        476 | M-803          |            |                0
        508 | M-803          | ARC0032    |              504
        515 | N-0052         |            |                0
        516 | N-0052         |            |                0
        517 | N-0052         |            |                0
        518 | N-0052         |            |                0
        519 | N-0052         | 42 FDR 03  |              515

```

I want to order the query result like this

```
     the_id | company        |   abcd     | master_id
     -------+----------------+------------+------------------
        500 | M-803          |            |                0
        501 | M-803          |            |                0
        502 | M-803          |            |                0
        503 | M-803          |            |                0
        504 | M-803          |            |                0
        508 | M-803          | ARC0032    |              504
        505 | M-803          | 355 KKK 65 |                0
        507 | M-803          | 45 KK 526  |              505
        506 | M-803          | ARC0032    |              505
        476 | M-803          |            |                0
        515 | N-0052         |            |                0
        519 | N-0052         | 42 FDR 03  |              515
        516 | N-0052         |            |                0
        517 | N-0052         |            |                0
        518 | N-0052         |            |                0

```

First master id then detail fields grouped

Any ideas?