SQL Bug set " newid () problem in random order "

Source: Internet
Author: User
Sort | random | questions
/**==** 2. NEWID () problem in random sort **==**/--test data declare @t table (name char (1), value int) insert INTO @tselect ' a ', 1union all select ' A ', 2unio n All select ' B ', 3union all select ' B ', 4union all select ' C ', 5union all select ' C ', 6

--require, random sort, but the same name to be ranked together select A.*from @t a Join (select Aa=newid (), name from (select distinct name from @t) a) b on a.name= B.nameorder by B.aa,newid ()

One of the/*--test results did not meet the requirements. If you change the join to a left right full join, the correct name value---------------B 4b 3c 5a 1a 2c 6

(The number of rows affected is 6 rows)--*/


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.