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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting "numbers" that are not INTs 1

Status
Not open for further replies.

jmreinwald

Technical User
Jun 3, 2002
46
US
Confused? I have a trading card database I'm working through. Each card in the set has a number associated with it, but not all numbers are, well, digits. Some set numbers may be alpha characters as well, such as P-JJ. Because of the varying number of characters, I have the field defined as a varchar(8). I need a way to ORDER BY that won't sort something like

1
10
100
101
102

and so on.
 
MySQL automatically converts numbers to strings as necessary, and vice versa.

mysql> SELECT 1+'1';
-> 2
mysql> SELECT CONCAT(2,' test');
-> '2 test'

so how bout somthing like this, for example:

Code:
SELECT card FROM tradingTable ORDER BY (card + 0);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top