我有一个表格,长这个样子:
id url title
1 http://afef.com/abc/def/gje/qkd hello
2 http://afe.com/?a=3&b=2&fse=3 hello
3 http://stackoverflow.com/fefw/sefac/fsg hello-world
从这里开始,id
是主键并且自动递增,url
是唯一的,但是title
可以重复。
从这个角度来看,当我向此表中添加新的URL时,比如说:
INSERT IGNORE INTO table (url, title)
VALUES ('http://abcd.com/affefef/sfsaa/?a=3', 'this is title')
如果是要插入新的URL,那就没问题了。但如果是重复的URL,它将被忽略,我就不知道重复的URL的id是什么。
id
必须保持不变。
有没有办法在一次查询中插入重复的URL时知道id
?
select insert
。 - Beginner