Home Machine Learning Do Not Put Filtering Circumstances Within the “WHERE” Clause in Some Situations | by Christopher Tao | Feb, 2024

Do Not Put Filtering Circumstances Within the “WHERE” Clause in Some Situations | by Christopher Tao | Feb, 2024

0
Do Not Put Filtering Circumstances Within the “WHERE” Clause in Some Situations | by Christopher Tao | Feb, 2024

[ad_1]

Do you what occurs if we put situations after LEFT JOIN ON?

So long as you click on into this text, I’m fairly positive it is best to perceive SQL. You should additionally perceive that we should always put our situations within the WHERE clause in a SELECT question. Nevertheless, let me ask you a query and see in the event you can reply it instantly.

What is going to occur if we put a filter situation with LEFT JOIN … ON … clause?

SELECT *
FROM Worker e LEFT JOIN Division d
ON e.dept_id = d.id
AND e.title = 'Chris'

In case you are uncertain concerning the behaviour of the above question or suppose it’s equal to the next one, please learn my article and I’ll let you know why they’re totally different.

SELECT *
FROM Worker e LEFT JOIN Division d
ON e.dept_id = d.id
WHERE e.title = 'Chris'
Picture by NoName_13 from Pixabay

For demonstration functions, I’ve created two tables with easy dummy information as follows.

The Worker Desk

The Division Desk

Now, let’s run the primary question within the introduction. On your reference, I’ll put the question right here once more.

SELECT *
FROM Worker e LEFT JOIN Division d
ON e.dept_id = d.id
AND e.title = 'Chris'

That was the reply. Have been you proper? 🙂

Only for comparability functions, I’ll additionally put the 2nd question and its outcomes right here. Of…

[ad_2]