i have a table MEN in sql server 2008 that contain 150 rows.
how i can show only the even or only the odd rows ?
thank\'s in advance
To select an odd id from a table:
select * from Table_Name where id%2=1;
To select an even id from a table:
select * from Table_Name where id%2=0;
FASTER: Bitwise instead of modulus.
select * from MEN where (id&1)=0;
Random question: Do you actually use uppercase table names? Usually uppercase is reserved for keywords. (By convention)
odd number query:
SELECT *
FROM ( SELECT rownum rn, empno, ename
FROM emp
) temp
WHERE MOD(temp.rn,2) = 1
even number query:
SELECT *
FROM ( SELECT rownum rn, empno, ename
FROM emp
) temp
WHERE MOD(temp.rn,3) = 0
For even values record :
select * from www where mod(salary,2)=0;
For odd values record:
select * from www where mod(salary,2)!=0;
To fetch even records
select *
from (select id,row_number() over (order by id) as r from table_name) T
where mod(r,2)=0;
To fetch odd records
select *
from (select id,row_number() over (order by id) as r from table_name) T
where mod(r,2)=1;
Following is for fetching even number:: Select * from MEN where Men_ID%2=0;
Following is for fetching odd number:: Select * from MEN where Men_ID%2!=0;
Here MEN is your table_name Men_ID is the column in MEN Table.