PostgreSQL için Rastgele Kayıt Alma
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
Microsoft SQL Server için Rastgele Kayıt Alma
SELECT TOP 1 column FROM table
ORDER BY NEWID()
IBM DB2 için Rastgele Kayıt Alma
SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
Oracle için Rastgele Kayıt Alma
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
Kaynak Belirtelim : http://www.petefreitag.com/item/466.cfm
Arkdaşlar ben MS SQL kullanıyorum.
Örnek olması amacıyla yazdığım kodu paylaşıyorum.
declare @ImageTypeID int;
set @Amount = 10;
declare @ImageTypeID int;
set @ImageTypeID = (select ID from [File.Images.Types] where Code = 'MultimediaImage');
IF @Amount IS NULL
BEGIN
set @Amount = 10;
END
SELECT TOP (@Amount) I.*, M.ID as MultimediaID, MC.Title as MultimediaTitle, IC.Title as ImageTitle, IC.PageTitle, IC.Keywords, IC.Description FROM [File.Images] as I
inner join [Modules.MultiMedia] as M on M.ID = I.ContentID
left join [Modules.MultiMedia.Contents] as MC on MC.MultimediaID = M.ID
left join [File.Images.Contents] as IC on IC.ImageID = I.ID and IC.LanguageID = @LanguageID
where
MC.LanguageID = @LanguageID and
TypeID = @ImageTypeID ORDER BY NEWID()
Kolay gelsin.
Yorumlar
Ortalama