Home » SQL & PL/SQL » SQL & PL/SQL » Delete records with limit
Delete records with limit [message #287124] Tue, 11 December 2007 02:34 Go to next message
juicyapple
Messages: 92
Registered: October 2005
Member
Hi,

I have create a table event (id INT, userName VARCHAR(50), accessTime DATETIME).

select * from event;

id userName accessTime
----- ---------- ---------------------
1 X 2007-10-23 15:02:05
2 A 2007-02-02 15:37:10
5 E 2007-11-23 01:20:10
6 D 2007-11-24 14:17:27
12 E 2007-11-24 14:17:27
13 D 2007-12-01 01:01:01

When SELECT count(*) FROM EVENT > 5, I want to delete the earlier record and keep the table has only 5 rows of record.

Is there any good way to do this if not using loop? Thanks.
Re: Delete records with limit [message #287129 is a reply to message #287124] Tue, 11 December 2007 02:47 Go to previous message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
1/ create a statement that find the 5 earliest rows or that exclude these rows
2/ modify the select to a delete

SQL Reference will be of great help to know the statement syntax.

Regards
Michel
Previous Topic: How to search a string in a text file
Next Topic: problem while selecting from multiple table
Goto Forum:
  


Current Time: Thu Dec 08 22:04:43 CST 2016

Total time taken to generate the page: 0.07652 seconds