Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ORDER BY question 1

Status
Not open for further replies.

3dColor

Programmer
Jan 10, 2006
240
US
Code:
ORDER BY planType DESC

When I set up my DB tables a while back I setup a "planType" which could have the values:

Premium
Bold
Basic

Now I would like to sort my rows by planType, however I would just like to sort first by Premium and then every thing else (meaning Bold and Basic would sort the same).

When I sort by planType DESC it works for Premium being sorted the first because of the P is after the B's. But how do I get Bold and Basic to sort the same?

 
Tony, thanks that worked great.

Do you know of any good MySQL books that would have answer a question like this one, or does it just take working with MySQL for years to know all these little "tricks"?
 
That's not really a trick, just a programmer's short-cut. The expression "plantype='Premium'" evaluates to 1 (true) or 0 (false), so can be used anywhere a numeric/boolean expression is expected. You could instead have used an IF or CASE expression.

There are a few good books on MySQL; P. DuBois's "MySQL" (Developer's Library) is often regarded as the best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top