Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

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)

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
10-01-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 12:44 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006