PDA

View Full Version : Multiple Sort Order using Like


jayemvee
04-29-2008, 12:27 AM
I am having an issue where two very similar queries... Are giving drastically different results.

The first:

SELECT * FROM docindex WHERE HWValues='Prostate' GROUP BY HWID ORDER BY MetaDataType ASC, DocumentType ASC LIMIT 1000;

The Second:

SELECT * FROM docindex WHERE HWValues Like('Prostate%') GROUP BY HWID ORDER BY MetaDataType ASC, DocumentType ASC LIMIT 1000;

In the first I am using WHERE, to pull exact matches from the index. When I try to use Like on the index, it completely ignores the second ORDER BY clause.

Any thoughts on why this is happening? Or are there any solutions? Thanks.

jayemvee
04-29-2008, 01:24 AM
This was a stupid mistake. I have had this problem for about a week now.

Here's the solution

The column, was full of numbers but some text, so I set it as varchar. Well it just so happens. It thought 10, should come before 2, 3, 4 etc...


Makes sense based on the data type.

-J