gpt4 book ai didi

MYSQL 通过 URL 选择

转载 作者:可可西里 更新时间:2023-11-01 08:09:54 25 4
gpt4 key购买 nike

我有一个看起来像这样的表:

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是主键和auto_increment,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

最佳答案

条件检查有助于获取重复 ID

检查这段代码:

 mysql.query("SELECT id FROM table  WHERE url = 'http://abcd.com/affefef/sfsaa/?a=3", function(error, result, field) {
if(error) {
exist(error); //No error
} else if (result) {
if (result.length > 0){
console.log("Id exist:" + result['id']);
}else{

// write your insert statement here
}
}
});

关于MYSQL 通过 URL 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40602584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com