Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Order by newid () what is the method of random query in various databases

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about the method of random query of various databases by order by newid(). Many people may not know much about it. In order to let everyone know more, Xiaobian summarized the following contents for everyone. I hope everyone can gain something according to this article.

SQL Server:

Select TOP N * From TABLE Order By NewID() view plaincopy to clipboardprint? Select TOP N * From TABLE Order By NewID()

Select TOP N * From TABLE Order By NewID()

The NewID() function creates a unique value of type uniqueidentifier.

The effect of the above statement is to read N records randomly from Table.

Access:

The code is as follows:

Select TOP N * From TABLE Order By Rnd(ID) view plaincopy to clipboardprint? Select TOP N * From TABLE Order By Rnd(ID)

Select TOP N * From TABLE Order By Rnd(ID)

Rnd(ID) where ID is an auto-numbering field and can be done with any number, such as the Name field (UserName)

Select TOP N * From TABLE Order BY Rnd(Len(UserName)) view plaincopy to clipboardprint? Select TOP N * From TABLE Order BY Rnd(Len(UserName))

Select TOP N * From TABLE Order BY Rnd(Len(UserName))

MySql:

The code is as follows:

Select * From TABLE Order By Rand() Limit 10 view plaincopy to clipboardprint? Select * From TABLE Order By Rand() Limit 10

Select * From TABLE Order By Rand() Limit 10

postgreSQL:

The code is as follows:

select * from glxt022 order by random() limit 5 view plaincopy to clipboardprint? select * from glxt022 order by random() limit 5

After reading the above content, do you have any further understanding of the random query methods of various databases by order by newid()? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report