Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 QUERY

Author  Topic 

Vipps
Starting Member

4 Posts

Posted - 2006-09-06 : 08:19:03
I Have A problem in a query the problem is that i want to delete all records from m table but not last one.
i want to do it with query only.
Any 1 Help me.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-06 : 08:20:27
delete from mytable where myprimarykeycolumn <> (select max(myprimarykeycolumn) from mytable)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-09-06 : 08:25:58
delete from [table] t1 where dt <> (select max(dt) From [table] t2 Where t1.pk = t2.pk)

Chirag
Go to Top of Page

Vipps
Starting Member

4 Posts

Posted - 2006-09-06 : 08:44:43
Thx A Lot PASO Query Works Fine
Go to Top of Page

Vipps
Starting Member

4 Posts

Posted - 2006-09-06 : 08:45:24
Thx A Lot Chirag Query Works Fine

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-06 : 09:19:52
There is no Last record until you define it

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-06 : 10:13:17
Yeah, what do you mean by last?

Read the hint link in my sig....

The physical order of data in a database has no meaning



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -