View Full Version : setting the ORDER BY
mull300
02-09-2006, 07:13 AM
ok say a field name in a table is called "type" and there are 4 possible values for the "type" field (car, boat, motor, rv). I dont want to order it by ascending or descending i want all the rows labled car under the "type" field to apear first. and the same for rv, boat, and motor. How would i acieve this??
fif you would normalise your db, then this would be quite simple.
you then just use the values 1, 2, 3, 4 as the foreign keys for the type-table, where car has PK value 1, rv has the PK value 2 etc.
in your select, you can then just have ORDER BY type ASC.
or you can add a column in the type-table with the order-value
mull300
02-09-2006, 05:29 PM
that doesnt solve my problem i can order them now by asc and desc but i want to the query how to order it. Even with the numbers i would want to say pull all number 2's first or in my case pull all rows with type=car first then the rest.
reread my post --> inside your type-table, you can have a column for every sortorder you desire.
by joining the two tables and then using the column you want to use for the sorting inside your ORDER BY clause, you can get the returned records in whatever order you can think up.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.