Select语句按记录的原始顺序除重,遇到个问题
希望按记录的原始顺序(注:顺序有些敏感,不能变前后顺序),给Name字段除重,习惯用这种代码:select * from MyTable A where not exists (select * from MyTable B where B.Name = A.Name and B.ID < A.ID)
现遇到一个问题,当ID字段也有重码时,如何表示?若改为where B.Name = A.Name and B.ID <= A.ID,似乎连自身也排除在外了,结果得到一个空集?
DeepSeek给出3个建议,都是幻觉,没法用。
仍想用一个语句来解决此问题,怎么破?
PS:打算改成这样子,可惜VFP提示出错,找不到M字段或N字段:
select A.*, recno() as M from MyTable A where not exists (select B.*, recno() as N from MyTable B where B.Name = A.Name and (B.ID < A.ID or (B.ID = A.ID and M < N)))