You are here: Re: SQL Union Problems When Trying to Retrieve Random Records « MsSQL Server « IT news, forums, messages
Re: SQL Union Problems When Trying to Retrieve Random Records

Posted by Alexander Kuznetsov on 06/07/06 13:51

>
> select col1, col2, col3, col4, col5, col6
> from (SELECT TOP 1 col1, col2, col3, col4, col5, col6
> from table2
> where col2 = @variable2
> order by newID()) AS d
>

Erland,

My server has crashed and I cannot verify it right now, but I have a
feeling that newID() will be calculated for every row, which may be
inefficient. I was thinking of a more efficient way to get a random
row. Suppose there is an identity column, then you could
do something like this to get a random identity:

select min(id) from table2,
(select max(id) maxID, min(ID) minID from table2) t
where table2.id > t.minID + (t.maxID - t.minID)*rand()

What do you think?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация