Home > Net >  how to do two sql queries in 1
how to do two sql queries in 1

Time:10-27

I have this right now:

 var userLogin = "select * from users where username = ?";
ibmdb.open(ibmdbconn, function(err, conn) {
    if (err) return console.log(err);
    conn.query(userLogin, [inputUsername], function(err, rows) {
        if (err) {
            console.log(err);
        }

        //if the query returns results that are > 0
        if (rows.length > 0) {
            alert("There is an account already registered with this email account")
        }
        conn.close(function() {
            // console.log("closed the function /login");
        });
    });
});

however, what I am trying to do is check if either the username or the email address exist already. If so, then alert. But that requires me to do two sql queries in one. Is this possible with the current setup I have?

I guess i would need something like:

select * from users where username && email = ?
 ...

CodePudding user response:

You would simply check that the input doesn't exist in either column SELECT COUNT(*) FROM users where username = $inputUserName OR email = $inputUserName

CodePudding user response:

Use the OR operator: https://www.geeksforgeeks.org/sql-and-and-or-operators/

SELECT * FROM Users WHERE username = ... OR email = ...

  • Related