so i have two tables, one is RAWtable and the other is MAINtable, I have to get the latest groupID if there
are more than one records exist (comparing same name, code). For example, I have this on RAWtable:
id groupid name code
1 G09161405 Name1 Code1
2 G09161406 Name1 Code1
the two records should be treated as one and should return this value only:
id groupid name code
2 G09161406 Name1 Code1
This row is the only row that shiuld be inserted in the main table. Provided returning the latest GroupID (the groupid is the combination of date and time)
I've tried this but its not working:
SELECT MAST.ID, MAST.code, MAST.name FROM RAWtable AS MAST INNER JOIN
(SELECT code, name, grouid,id FROM RAWtable AS DUPT GROUP BY code, name, groupid,id HAVING COUNT(*) >= 2) DUPT
ON DUPT.code =MAST.code and DUPT.name =MAST.name where dupt.groupid >mast.groupid
how can i do this? thanks a lot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…