{"id":6411,"date":"2017-04-18T08:47:07","date_gmt":"2017-04-18T08:47:07","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=6411"},"modified":"2017-04-20T11:21:39","modified_gmt":"2017-04-20T11:21:39","slug":"how-to-select-n-random-records-from-a-sql-server-table","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/tips\/how-to-select-n-random-records-from-a-sql-server-table.html","title":{"rendered":"How to select N random records from a SQL Server table"},"content":{"rendered":"<p>If you want to select N random records from a SQL Server table, you need to change the clause as follows:<\/p>\n<p><strong>select top N * from tableName order by newid()<\/strong><\/p>\n<p>For example, to select 5 random customers in the customers table, you use the following query:<\/p>\n<p><strong>select top 5 * from customers order by newid()<\/strong><\/p>\n<p>Some SQL Server tools you can try: <a href=\"https:\/\/www.withdata.com\/sql-server\/\"> https:\/\/www.withdata.com\/sql-server\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to select N random records from a SQL Server table, you need to change the clause as follows: select top N * from tableName order by newid() For example, to select 5 random customers in the customers table, you use the following query: select top 5 * from customers order by newid() [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[1964,1321],"class_list":["post-6411","post","type-post","status-publish","format-standard","hentry","category-tips","tag-random-records","tag-sql-server"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/6411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=6411"}],"version-history":[{"count":3,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/6411\/revisions"}],"predecessor-version":[{"id":6487,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/6411\/revisions\/6487"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=6411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=6411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=6411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}