Query for selecting even/odd/random row selection

-random selection
--SQL Server
SELECT TOP 1 * FROM
ORDER BY NEWID()

-- Oracle
SELECT column FROM ( SELECT FROM

ORDER BY dbms_random. value )
WHERE rownum = 1

--row_number( )is available in sqlserver2005 only
--this is for odd rows
--sqlserver
select * from table where row_number() %2=1
--this is for even rows
--sqlserver
select * from table where row_number() %2=0

--this is for odd rows
-- Oracle
select * from table where rownumber%2= 1 --or rowid%2=1

--this is for even rows
-- Oracle
select * from table where rownumber%2= 0 --or rowid%2=0

Comments

Popular posts from this blog

DRINK WATER ON EMPTY STOMACH

How To Negotiate the Perfect Salary

Adding Responsibility