Group By Clause

  • 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.

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply