PDA

View Full Version : ordered select query help.


bazz
02-08-2008, 04:10 PM
Hi,

I am trying to select three fields from one table and to get each of the range of values, ordered 'alphanumerically'.

Please point me to a MySQL key word (eg DISTINCT, UNIQUE SUM COUNT etc) (I now its none of them lol), which can change this table layout to the results shown below.

tbl_types

type | sub_type | category |
Accommodation | Hotel 5 Star |
Accommodation | Guesthouse | 3 Star |
Accommodation | Bed and Breakfast | Certified |
Accommodation | Hotel | 3 star |

This table will always have jumbled up records because new types are added as required.

I want the output to be like this (well, with Accommodation only showing once - so without duplicates).

Accommodation - Bed and Breakfast - Certified
Accommodation - Guesthouse - 2 Star
Accommodation - Guesthouse - 3 Star
Accommodation - Guesthouse - 4 Star
Accommodation - Guesthouse - 5 Star
Accommodation - Hotel - 2 Star
Accommodation - Hotel - 3 Star
Accommodation - Hotel - 4 Star
Accommodation - Hotel - 5 Star
Attractions - Cultural - Architectural
Attractions - Recreation - Wildlife

See how each record is alphabetical or numerically ordered in line wioth its previous field.

I don't know the name of what I am looking for.

bazz

Andrew Johnson
02-08-2008, 04:38 PM
ummm... maybe:


SELECT type,sub_type,category FROM tbl_types ORDER BY type,sub_type,category

bazz
02-08-2008, 05:28 PM
That seems to do the trick. Thank you :thumbsup:

bazz

Andrew Johnson
02-08-2008, 08:46 PM
No problem