Quantcast
Channel: Select n random rows from SQL Server table - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by VISHMAY for Select n random rows from SQL Server table

$
0
0

I was using it in subquery and it returned me same rows in subquery

 SELECT  ID ,            ( SELECT TOP 1                        ImageURL              FROM      SubTable               ORDER BY  NEWID()            ) AS ImageURL,            GETUTCDATE() ,            1    FROM    Mytable

then i solved with including parent table variable in where

SELECT  ID ,            ( SELECT TOP 1                        ImageURL              FROM      SubTable               Where Mytable.ID>0              ORDER BY  NEWID()            ) AS ImageURL,            GETUTCDATE() ,            1    FROM    Mytable

Note the where condtition


Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>