2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

select even records from a table in sql

In my table i have 2 records for every customer.One record will have amount info. 2nd record will contains interest information.

So every time i want to display 2nd record of every customer.How can i get this.Please help me in this

userimage

If every customer is having 2 record and 2nd records is interest only then you candirectly use below query to get 2nd record of every customer


SELECT * FROM table_name WHERE (ROWID,0) IN (SELECT ROWID,MOD(ROWNUM,2) FROM table_name);

It will gives you records which are having ever rownum.

If you want odd records then you can use below.

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

Answer is