SQL To Sort 2 columns, one with dupes

  • Or maybe you need to type a little faster... but that one was a close call.

    Talking about call, the week-end is calling here.

    L8r guys.

  • Yes I did try your query and it appeared not to work.

    Upon closer examination I know why - If the ID is the same but the Name is different it will list the ID twice. How can we get it to only consider the ID and not the NAME?

    Also, out of curiosity, what purpose does the MIN() server? Is this just for the GROUP by to work?

    Thanks you've been a big help so far..... If you can solve this last part I'd be really grateful...

  • Then remove Name

    Select id,  Min(SortOrder) as MinSort from @A

    group by id

    order by MinSort

    BTW the min() will give you the minimum value within the group of columns in the group by

     


    * Noel

  • Is there a way to see the Name though - I need it on the report as well....

    Thanks.....

  • If you have Several Names for the same ID which of the Names are you supposed to show ?

     


    * Noel

  • If you have several items with the same id with different meaning, you don't have a table and therefore cannot be queried. Try to fix the data first then the query will work.

  • It doesn't matter which of the dupes I show...... Any ideas? This is a one time thing, so it is probably not worth the time to normalize the table.....

    Thanks much....

  • Then please post the ddl, the full data dml (enough to make the query work) and we'll see what we can do.

    dml = INSERT STATEMENTS

  • Well, I figured out a way... I created a temp table with the ouput'd Id's, then did a join to the main table...

    Thanks to everyone for all the help.....

    Mike

Viewing 9 posts - 16 through 24 (of 24 total)

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