I have two tables as shown here.
I am trying to fetch name and register variable WHEN register variable doesn’t hold value present.
Using below query what I get is shown here.
SELECT t2.name, t1.register, t1.mydate
FROM time t1
RIGHT JOIN user t2
ON t2.user_id=t1.user_id
WHERE (t1.register = 'absent' OR t1.register is null)
When I use below query I get INCORRECT result as shown here.
SELECT t2.name, t1.register, t1.mydate
FROM time t1
RIGHT JOIN user t2
ON t2.user_id=t1.user_id AND (t1.register = 'absent' OR t1.register is null)
My question is: Why I am getting different result in above cases. I am using WHERE condition in ON clause itself so that I don’t need to write WHERE condition.
Can someone point me in right direction?
if you put the
"t1.register = 'absent' OR t1.register is null"condition in the WHERE clause, it applies after the join, whereas if you put it in the ON clause, it impacts the join.It is absolutely normal and desired behavior 🙂
Here you have to put it in the WHERE clause 🙂