idAuthenticate | username | password
1 john letmein
idClient | Enabled | idAuthenticate
1 Yes 1
My query is returning zero if say somethin like this:
client ON authenticate.idAuthenticate = client.idClient
authenticate.username = 'john'
authenticate.password = 'letmein'
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).
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?
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 ?