SQLTeam.com | Weblogs | Forums

Data is not sorted even it has a priamry key


#1

DATA IS NOT SORTED EVEN IT HAS A PRIMARY KEY.

PLEASE LET ME KNOW THE FUNDA BEHIND IT.


#2

Because Brand_ID column is a string type ( varchar(12) ), the sorting is string sort. In string sort, comparison is done one character at a time, starting with the leftmost character. So 2 is greater than 1 in string sort. But 2 is greater than 10 as well.

DATA IS NOT SORTED EVEN IT HAS A PRIMARY KEY.

Having a primary key does not guarantee sort order in your query results. You have to add an ORDER BY clause to your query to make sure that it is sorted by whatever rule you want to use.


#3

thanks for your response.