Select alternate rows from SQL Server table -


i working sql server 2008. have table not contain unique columns; how alternate rows it?

sql server table:

+-----+--------+ |  id |  name  | |-----+--------| |  1  |  abc   | |  2  |  pqr   | |  2  |  pqr   | |  3  |  xyz   | |  4  |  lmn   | |  5  |  efg   | |  5  |  efg   | +-----+--------+ 

as we've come @ least 1 working suggestion question, i've tried below code; not proper technique when fetching huge amount of data.

trial:

create table #tmp (     id int, name varchar(10), srno int )  insert #tmp    select        id, name,       row_number() on (order id) % 2 srno   --,alternate rows           employee  select *  #tmp  srno = 1 --or srno = 0 

above query gives out alternate rows i.e. 1st, 3rd, 5th or 2nd, 4th, 6th etc.

please me out proper way without #tmp achieve goal!

thank you!

you can use select statement in-line view. don't need #tmp table.

select t.id, name (select id, name, row_number() on (order id) srno employee) t (t.srno % 2) = 1 

sqlfiddle


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -