What I have here is a table with around 600.000 rows. In the table I have an integer column "uid" and a varchar column "ex_id" which is the one that has duplicate entries (at least 2 times the same "ex_id"). The problem is, that I need the newer entry of the dublets.
So I figured I could join with another table (also around 600.000 rows), where I have a Datetime column and also the "uid" column. Is there a way to do this in SQL so that it doesn't take forever to run that command? I've tried different approaches with JOINS and GROUP BYs but either they didn't work or they ran forever and never got a working result.
TLDR: I want to delete older duplicates in a 600.000 rows table and have to join with another 600.000 rows table to find the older ones. Is this possible to do in SQL with feasible runtime or do I have to use PHP?
EDIT: A little more information on the table structure:
[
{
'id' : 1,
'select_type' : 'SIMPLE',
'table' : 'a',
'type' : 'ALL',
'possible_keys' : NULL,
'key' : NULL,
'key_len' : NULL,
'ref' : NULL,
'rows' : 569418,
'Extra' : ''
},
{
'id' : 1,
'select_type' : 'SIMPLE',
'table' : 'x',
'type' : 'eq_ref',
'possible_keys' : 'PRIMARY',
'key' : 'PRIMARY',
'key_len' : '8',
'ref' : '---.a.user_id',
'rows' : 1,
'Extra' : 'Using where'
},
{
'id' : 1,
'select_type' : 'SIMPLE',
'table' : 'b',
'type' : 'ALL',
'possible_keys' : NULL,
'key' : NULL,
'key_len' : NULL,
'ref' : NULL,
'rows' : 569418,
'Extra' : 'Using where; Using join buffer'
},
{
'id' : 1,
'select_type' : 'SIMPLE',
'table' : 'y',
'type' : 'eq_ref',
'possible_keys' : 'PRIMARY',
'key' : 'PRIMARY',
'key_len' : '8',
'ref' : '---.b.user_id',
'rows' : 1,
'Extra' : 'Using where'
}
]