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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -