• SanjayAttray (4/22/2009)


    select NULL,'manoj'union select Null,'1'union select NULL,'manoj'

    order by 2

    or

    select NULL,'manoj'union select Null,'1'union select NULL,'manoj'

    order by 1

    gives you same result.

    NULL1

    NULLmanoj

    I tried on all sql server versions and result is same. May be I am missing something here when some people are telling both 1 & 2 answers are correct.

    Try actually specifying an "order by" that can be honored by the dbms:select NULL,'manoj'

    union select Null,'1'

    union select NULL,'manoj'

    order by 2 desc

    This returns the same two rows in a different order:

    ----------- -----

    NULL manoj

    NULL 1

    (2 row(s) affected)

    So, the difference between the two 2-rows-returned answers comes down to whether you assume the same collation was chosen (or accepted) at installation time. I lost the point because as a mainframe programmer I've got EBCDIC stuck in my head and figured that letters would sort before numbers. But even as I thought that, I was grumbling to myself that without an "order by", it's a crap-shoot between the two.