user7159879 user7159879 - 1 year ago 79
Node.js Question

MYSQL select by URL

I have a table looks like this:

id url title
1 hello
2 hello
3 hello-world

from here
is primary key and auto_increment, and
is unique, but
can be duplicated.

From this point of view, when I add new URL to this table, like :

INSERT IGNORE INTO table (url, title)
VALUES ('', 'this is title')

Then, if it is new URL to insert, it doesn't matter. But if it is duplicated URL, it will be ignored and I can't know what the duplicated URL's

must not be changed.

Is there any solutions to know
when I INSERT duplicated URL with one query ?

zan zan
Answer Source

Conditionally checking would help in getting duplicate ID

Check this code:

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

                // write your insert statement here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download