Quantcast
Viewing latest article 5
Browse Latest Browse All 20

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

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 latest article 5
Browse Latest Browse All 20

Trending Articles