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
Post a Comment