SQL ORDER BY not working

Hey,

I have the following SQL query:

SELECT * FROM tablename ORDER BY name ASC

It gives me this result:

http://www.glofamily.com/order.jpg

Why is “Irlam” at the top? It should be after Heywood…

Any ideas why the ORDER BY does not work how it should be?

Thanks

I had the same problems many times I now use TRIM for my inserts

LTRIM(String)

could you please dump those rows for us, i.e. produce the CREATE TABLE and INSERT statements

thanks

see, isn’t that interesting, i didn’t even have to test anything

the problem is sitting right there in front of you in plain sight

there’s a space at the front of Irlam

and as you know, spaces sort higher than alpha characters

:cool:

Of course:

Here you go:


CREATE TABLE IF NOT EXISTS `tbl_stockistscategories` (
  `ID` int(11) NOT NULL auto_increment,
  `name` varchar(800) NOT NULL,
  `date_added` datetime NOT NULL,
  `deleted` int(11) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;

--
-- Dumping data for table `tbl_stockistscategories`
--

INSERT INTO `tbl_stockistscategories` (`ID`, `name`, `date_added`, `deleted`) VALUES
(5, 'Bury', '2010-06-18 17:20:49', 0),
(4, 'Bramhall', '2010-06-18 17:19:35', 0),
(3, 'Altrincham', '2010-06-18 17:15:45', 0),
(6, 'Chorlton', '2010-06-18 17:20:57', 0),
(7, 'Didsbury ', '2010-06-18 17:21:06', 0),
(8, 'Heywood ', '2010-06-18 17:21:17', 0),
(9, ' Irlam ', '2010-06-18 17:21:26', 0),
(10, 'Knutsford ', '2010-06-18 17:21:35', 0),
(11, 'Littleborough ', '2010-06-18 17:21:49', 0),
(12, 'Macclesfield  ', '2010-06-18 17:22:00', 0),
(13, 'Manchester ', '2010-06-18 17:22:10', 0),
(14, 'Oldham ', '2010-06-18 17:22:19', 0),
(15, 'Salford ', '2010-06-18 17:22:28', 0),
(16, 'Stockport  ', '2010-06-18 17:22:36', 0),
(17, 'Trafford ', '2010-06-18 17:22:44', 0),
(18, 'Warrington ', '2010-06-18 17:22:53', 0),
(19, 'Wigan  ', '2010-06-18 17:23:00', 0),
(20, 'Wilmslow  ', '2010-06-18 17:23:08', 0),
(21, 'Cheadle', '2010-07-15 13:54:36', 0),
(22, 'Cheshire', '2010-07-15 13:54:46', 0),
(23, 'Bolton', '2010-07-15 13:54:53', 0),
(24, 'Heaton Moor', '2010-07-15 13:55:04', 0),
(25, 'Sale', '2010-07-15 13:55:14', 0);

huh? Can someone please help, who has an idea of why this does not work?

Thanks

:smiley: Thanks haha.

Can’t believe that was the problem…

Thanks again