sql - MySQL SubQuery doesn't seem to work -
i have database table named "married" consist of numerous fields, 2 fields in particular make-up table primary-key. 2 field names are; "number", "date".
there many records in duplicate share same "number" have different "dates" associated.
i need delete record (row) within each pair, "number" common between two, has older "date" associated. there goes wrong in query.
delete number married number in(select number married) , date <any( select date married)
you want delete recent date each number. in mysql, limited in use of table deletions occurring in rest of query. fortunately, can around using join
. think want:
delete m married m join (select number, max(date) maxd married group number ) tokeep on m.number = tokeep.number , m.date < tokeep.maxd;
Comments
Post a Comment