idAuthenticate | username | password
1 john letmein
Table Client:
idClient | Enabled | idAuthenticate
1 Yes 1
My query is returning zero if say somethin like this:
SELECT
authenticate.idAuthenticate,
authenticate.username,
authenticate.password,
client.idClient,
client.Enabled
FROM
authenticate
LEFT JOIN
client ON authenticate.idAuthenticate = client.idClient
WHERE
authenticate.username = 'john'
AND
authenticate.password = 'letmein'
AND
client.Enabled = 'Yes';
but works if I remove client.Enabled = ‘Yes’; from the query. so my query is not right, does anyone know how to do it?
Is this query in the .php page, or straight from the DB? You have a semicolon on the last statement, and if you we’re running it out of the webpage, that would cause an error. Then again, I could be wrong.
Put any conditions on the left joined table in the ON clause for that join.
If you put that condition in the WHERE clause, the left join becomes an inner join (at least as far as the results of the query are concerned).
This actually is not working. If Enabled = ‘No’, the query should return zero, but instead it returns 1 match, so I think the moving of AND Enabled = ‘Yes’ has made the query discard that condition.
It all depends on what you want.
You are using a left join, this means it’ll always return the rows found in the first table, regardless of what is found in the second table. If no corresponding row is found in the second table, then those columns will be NULL.
So why don’t you explain in plain english (not query) what you’re trying to do here?
I might be taking the miki out of you, but would you explain how the LEFT and RIGHT JOIN work for my specific tables. I just dont get the exact picture.
Use an INNER JOIN then.
If you don’t get any rows with enabled = ‘Yes’, and you do eliminating that check, then check the value of the enabled column in the clients table. Probably it isn’t ‘Yes’, but ‘yes’ or something like that
Edit: check your join criteria as well: you are joining on client.idClient. Shouldn’t that be client.idAuthenticate ?