...

View Full Version : simple question (order by)



markman641
08-19-2011, 09:47 PM
How do i make the following:


$get_name = mysql_query("SELECT `id`, `name`, `link`, `value`, `description` from `offers` WHERE `countries` like '%us%' LIMIT 0, 25");

How do i make that sort by ID from largest number to smallest number? idk where to put the order by

Old Pedant
08-19-2011, 11:02 PM
ORDER BY is always the *last* thing other than LIMIT. (Well, except for some esoteric options you are not likely to ever need.)

To sort from low to high, you use ORDER BY fieldname ASC
To sort from high to low, you use ORDER BY fieldname DESC

Except that ASC is optional, and is the default if DESC is not coded.

Here, read the docs:
http://dev.mysql.com/doc/refman/5.5/en/select.html

guelphdad
08-20-2011, 01:12 AM
SELECT
FROM
WHERE
GROUP BY
HAVING
LIMIT

as a quick reminder of the syntax order (for most uses)

Old Pedant
08-20-2011, 07:52 PM
Ummm...and ORDER BY?

SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
LIMIT

guelphdad
08-21-2011, 02:50 AM
Well yeah i should have included that but you had specifically told the OP where Order By clause went OP. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum