how to write the query to select the rows are in the order
of either 1,3,5,7... or 2,4,6,8,...

Answers were Sorted based on User's Feedback



how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / senthil

select * from dbo.outs_OpenItems where OIR_ID % 2=1

Is This Answer Correct ?    20 Yes 9 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / vijay sultampur

For 1,3,5,7...

select * from emp where (rowid,1) in (select rowid,mod
(rownum,2) from emp);

For 2,4,6,8,...

select * from emp where (rowid,0) in (select rowid,mod
(rownum,2) from emp);

Is This Answer Correct ?    7 Yes 0 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / rajesh verma

1> incase of 2,4,6,8,...

select col1,col2 from tab1 where col1 in
(Select case when Row_number() over (order by col1)%2=0
then col1 else 0 end from tab1)

2> in case of 1,3,5,7,....

select col1,col2 from tab1 where col1 in
(Select case when Row_number() over (order by col1)%2=1
then col1 else 0 end from tab1)

Is This Answer Correct ?    6 Yes 1 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / leo

with contactinfo as (
select contactid,firstname,row_number() over (order by
firstname)as row from person.contact
)
--select * from contactinfo where row % 2 =0

Is This Answer Correct ?    4 Yes 1 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / md. niyaz

For: 2, 4, 6, ......

select * from <Table_Name> where <Column_Name> % 2 = 0

==============Niyaz====================================

For: 1, 3, 5, ......

select * from <Table_Name> where <Column_Name> % 2 = 1

Is This Answer Correct ?    3 Yes 1 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / vijayplsql@gmail.com

For 1,3,5,7...

select * from emp where (rowid,1) in (select rowid,mod
(rownum,2) from emp);

For 2,4,6,8,...

select * from emp where (rowid,0) in (select rowid,mod
(rownum,2) from emp);

Is This Answer Correct ?    1 Yes 0 No

how to write the query to select the rows are in the order of either 1,3,5,7... or 2,4,6,8,.....

Answer / tiru

select * from
(select emp.ename, emp.age, (rownum+1) AS XX from employee
emp )
where remainder(XX,2) = 0;

select * from
(select emp.ename, emp.age, (rownum+1) AS XX from employee
emp )
where remainder(XX,2) = 1;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What do mean by xml datatype?

0 Answers  


How to Install SQL SERVER 2005 remotely?

1 Answers   IBM,


How to use wildcard characters in like operations in ms sql server?

0 Answers  


Which command is used for user defined error messages?

0 Answers  


Give some Scenario for Non Clusterd index? Can we write system defined functions in side The Function? Wat is the Unique Datatype?

0 Answers   Value Labs,






What is referential integrity and how is it achieved?

1 Answers   Adea Solutions,


can a table be moved to different filegroup? : Sql server administration

0 Answers  


explain different types of backups avaialabe in sql server? : Sql server database administration

0 Answers  


What are recommended options to be used while using db mirroring? : sql server database administration

0 Answers  


How to get @@error and @@rowcount at the same time?

0 Answers  


What is candidate key with example?

0 Answers  


How to convert a table data in XML format in sql server?

0 Answers  


Categories