Author Topic: Display every Nth record without using order by  (Read 1165 times)

0 Members and 1 Guest are viewing this topic.

Offline HumptyTopic starter

  • Enthusiast
  • Posts: 167
    • View Profile
Display every Nth record without using order by
« on: August 19, 2010, 11:01:54 PM »
G'day Guys,
As part of an assignment i need to display every 2nd record in the SQL.

I am lost and need a point in the right direction.  From a slight programming background I am thinking somehting like:

SELECT * FROM table STEP 1
- Humpty
  #> Where does the light go when it goes out?

Offline HumptyTopic starter

  • Enthusiast
  • Posts: 167
    • View Profile
Re: Display every Nth record without using order by
« Reply #1 on: August 20, 2010, 12:25:03 AM »
Got it. it was all in the SELECT DISTINCT on (field name), field, field etc...

Code: [Select]
select distinct on (t1.fixtureid)

       t1.fixtureid,

       t1.teamid,

       t1.score,

       t2.teamid,

       t2.score

  from results t1

  join results t2

    on t2.fixtureid = t1.fixtureid

 where t2.teamid != t1.teamid;
- Humpty
  #> Where does the light go when it goes out?