Unix Technical Forum

Re: filter for DELETE

This is a discussion on Re: filter for DELETE within the SQL Server forums, part of the Microsoft SQL Server category; --> On 30 Sep 2005 01:36:49 -0400, Joseph wrote: >Hi, >I don’t know to write SQL command filter. >m_strQueryDelete.Format("DELETE FROM ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 02:30 PM
Hugo Kornelis
 
Posts: n/a
Default Re: filter for DELETE

On 30 Sep 2005 01:36:49 -0400, Joseph wrote:

>Hi,
>I don’t know to write SQL command filter.
>m_strQueryDelete.Format("DELETE FROM tab WHERE (Col1 = ’abc’ AND Col2
>= ’abc’ AND ?????)"
>example: ODBC found 100 records.
>I need to delete first 90 records and to leave last 10 records.
>
>Thank you
>
>Joseph


Hi Joseph,

Define: "first 90". You see, tables in the relational model are, by
definition, UNordered collections of data. There is no such thing as
"first" or "last" until you define an ordering.

For example, if you have a column EntryDate in your table and you want
to delete the 90 oldest rows that have 'abc' in both Col1 and Col2, you
would use:

DELETE FROM tab
WHERE Col1 = 'abc'
AND Col2 = 'abc'
AND (SELECT COUNT(*)
FROM tab AS t2
WHERE t2.Col1 = 'abc'
AND t2.Col2 = 'abc'
AND t2.EntryDate <= tab.EntryDate) <= 90


Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:51 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com