no keys...

Started by Dorward Villaruzalmost 24 years ago3 messagesgeneral
Jump to latest
#1Dorward Villaruz
dorwardv@ntsp.nec.co.jp

i have a table where there is no primary key

i have 5 rows of data

day1 time1
day1 time1
day1 time2
day1 time2
day1 time2

time2 is newer than time1, how should i delete the four oldest record in the table. this means that the only row that will be left on my table is:

day1 time2

#2Jeff Davis
pgsql@j-davis.com
In reply to: Dorward Villaruz (#1)
Re: no keys...

Each row automatically has an oid assigned to it, which can act as a key. It's
sort of "hidden", but all you have to do is "select oid,* from mytable" to
see it. Then you can delete based on that oid.

Regards,
Jeff

Show quoted text

On Tuesday 16 April 2002 12:31 pm, Dorward Villaruz wrote:

i have a table where there is no primary key

i have 5 rows of data

day1 time1
day1 time1
day1 time2
day1 time2
day1 time2

time2 is newer than time1, how should i delete the four oldest record in
the table. this means that the only row that will be left on my table is:

day1 time2

#3scott.marlowe
scott.marlowe@ihs.com
In reply to: Jeff Davis (#2)
Re: no keys...

On Tue, 16 Jul 2002, Jeff Davis wrote:

Each row automatically has an oid assigned to it, which can act as a key. It's
sort of "hidden", but all you have to do is "select oid,* from mytable" to
see it. Then you can delete based on that oid.

Regards,
Jeff

On Tuesday 16 April 2002 12:31 pm, Dorward Villaruz wrote:

i have a table where there is no primary key

i have 5 rows of data

day1 time1
day1 time1
day1 time2
day1 time2
day1 time2

time2 is newer than time1, how should i delete the four oldest record in
the table. this means that the only row that will be left on my table is:

day1 time2

You can do something like this in sql:

delete from test where oid !=(select max(oid) from test group by time
order by time desc limit 1);