?
Solved

how can i delete the 4 last rows introduced when i have a datetime column?

Posted on 2009-12-18
6
Medium Priority
?
295 Views
Last Modified: 2012-05-08
hello experts,
i have a table with rows that i insert with a datatime column,
how can i delete the four last rows introduced?

thank you in advance.
0
Comment
Question by:toshi_
  • 4
  • 2
6 Comments
 
LVL 13

Assisted Solution

by:sameer2010
sameer2010 earned 1500 total points
ID: 26080086
Try this
DELETE FROM YOUR_TABLE
WHERE DATE_TIME IN (SELECT TOP 4 DATE_TIME FROM YOUR_TABLE ORDER BY DATE_TIME)

Open in new window

0
 
LVL 13

Accepted Solution

by:
sameer2010 earned 1500 total points
ID: 26080091
Missed DESC clause
DELETE FROM YOUR_TABLE
WHERE DATE_TIME IN (SELECT TOP 4 DATE_TIME FROM YOUR_TABLE ORDER BY DATE_TIME DESC)

Open in new window

0
 

Author Comment

by:toshi_
ID: 26081250
.hello sameer2010
sorry but the query is not working for me.

this is what i've been trying :

DELETE FROM rf_card_status WHERE date IN (SELECT TOP '4' date FROM rf_card_status ORDER BY date DESC)

with char quotes wrapping the 4 and without.

ERROR:  syntax error at or near "4"
LINE 1: ...ETE FROM rf_card_status WHERE date IN (SELECT TOP 4 date FRO...




0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:toshi_
ID: 26081263
select * from rf_cards_status limit 10 <- ok, but i can not add "order by desc"

thank you for further help.


0
 

Author Comment

by:toshi_
ID: 26081307
this would be the inner query,

select * from rf_card_status order by date desc
limit 4


here's my solution :
delete from rf_card_status where date in (select date from rf_card_status order by date desc
limit 4)

0
 

Author Closing Comment

by:toshi_
ID: 31667720
i had to look for adapting to postgresql
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
What we learned in Webroot's webinar on multi-vector protection.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question