Jump to content

need to order by make and model


attaboy

Recommended Posts

I have a table called inventory

mysql> SELECT * FROM inventory;

+------------+--------------------+--------+-----+

| make      | model              | price  | mpg |

+------------+--------------------+--------+-----+

| Ford      | Model T            |  22500 |  17 |

| Studebaker | Hawk              |  17500 |  20 |

| Volkswagen | Bug                |  19900 |  25 |

| Ace        | Continental        |  33900 |  12 |

| Lincoln    | Continental        |  33900 |  10 |

| Ford      | Model A            |  33995 |  18 |

| Packard    | Series 1604        | 112700 |  15 |

| AMC        | AMX                |  26995 |  21 |

| Nash      | Airflyte Statesman |  1500 |  13 |

| Lincoln    | Zephyr            |  1800 |  12 |

+------------+--------------------+--------+-----+

I need to order by make and model.  I tried this:

 

mysql> SELECT make, model, price
    -> FROM inventory
    -> WHERE make IN
    -> (
    ->    SELECT make
    ->    FROM inventory
    ->    ORDER BY model
    -> )
    -> ORDER BY make;

 

and this was the result, it's ordered by make but I need it to be ordered model under make so that

Ford Model A comes before Ford Model T

+------------+--------------------+--------+

| make      | model              | price  |

+------------+--------------------+--------+

| Ace        | Continental        |  33900 |

| AMC        | AMX                |  26995 |

| Ford      | Model T            |  22500 |

| Ford      | Model A            |  33995 |

| Lincoln    | Continental        |  33900 |

| Lincoln    | Zephyr            |  1800 |

| Nash      | Airflyte Statesman |  1500 |

| Packard    | Series 1604        | 112700 |

| Studebaker | Hawk              |  17500 |

| Volkswagen | Bug                |  19900 |

+------------+--------------------+--------+

 

 

Link to comment
https://forums.phpfreaks.com/topic/258571-need-to-order-by-make-and-model/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.