February 4, 2009 at 10:03 pm
hello all
i have a table which has say 3 columns
IDNUmber, Name,city
IDNumber Name City
1 3test Newyork
2 23test1 dallas
3 test4 atlanta
4 utest san jose
one of the control in the screen is using
Select name from table group by name
in that case...the name is not as shown in the order but it becames
different way
firstitem in dropdown might be test4,23test1,utest,3test
something like this
why is this happening and how to solve it please let me know.
February 4, 2009 at 10:45 pm
SQL Server, or any relational database system for that matter, doesn't put data in any specific order unless you tell it to.
the primary key of a table is used to keep the data in a specific order so it can be access quickly, and often affects the order of an unordered data set., so yeah it "seems" like they are in 1-2-3-4 order when you look at it...but a group by is a great example of how the data no longer gets returned in a specific order.
you can fix this by simply adding an order by clause to your sql:
Select name from table group by name ORDER BY name
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply