sql server - SQL: delete one (or all) record among 2 or more records with older date -


i want achieve this, not possible @ moment in sql server 2000.

delete      top 1       attendance       student_id = '201601292'  order      attend_date asc 

unintentionally, somehow duplicate records have been entered in table , want delete duplicates latest (or oldest) one.

note table has no primary key. sql server version 2000, 'with' keyword not available. also, 'attend_date' column datetime column.

simple answer, should work dbms:

delete attendance student_id = '201601292' , attend_date < (select max(attend_date)                    attendance student_id = '201601292') 

or, more general, students:

delete attendance a1 attend_date < (select max(attend_date)                    attendance student_id = a1.student_id) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -