Maciek
Maciek

Reputation: 1982

PDO query utilizing two tables with separate parameters

I have two tables. One with login information logins which holds password column and one with emails emails which holds email column and loginID column. I would like to use parameters on both tables. I would like to find row in emails where email=? and then take the corresponding login id inside that row and match this to a row in logins table. I would then like to match the password to the row in logins. A double separated where statement from two tables.

Something along the lines of:

$prepareTables=$listersDatabase->prepare("select*from emails where email=? left join logins on emails.loginID=logins.ID where password=?");
$prepareTables->execute(array("[email protected]","password123"));

Any help is appriciated

Upvotes: 0

Views: 35

Answers (1)

user4035
user4035

Reputation: 23729

Try this:

SELECT * 
FROM
    emails 
INNER JOIN logins 
ON emails.loginID=logins.ID 
WHERE 
    emails.email=?
AND
    password=?

I used INNER JOIN instead of LEFT JOIN as you have this table inside a WHERE condition anyway. You must put all your conditions inside one WHERE clause.

Upvotes: 1

Related Questions