Wednesday 29 September 2021

MYSQL | Replace HAVING With WHERE Condition | Use WHERE Clause Instead Of Having




MYSQL | Replace HAVING With WHERE Condition | Use WHERE Clause Instead Of HAVING Clause.
-------------------------------

QUERY EXAMPLE :-
SELECT * from (SELECT *,job_id+department_id as new_random_id FROM employees) random_table where new_random_id >=10 and new_random_id<=15

Subscribe my Channel:- 
http://www.youtube.com/user/SanketRooney?sub_confirmation=1 

Facebook Page:- 
https://www.facebook.com/UnpossibleNS 

Twitter Account:- 
https://twitter.com/UnpossiblePOG 

Blog:- 
https://unpossiblepog.blogspot.com/ 

Website:- 
https://unpossiblepog.com/ 

Gaming Instagram:- (@unpog.gaming)
https://www.instagram.com/unpog.gaming/
-------------------------------
Hey guys, in this video we shall learn how to use WHERE clause instead of HAVING clause.
The HAVING clause is mandatory when you use alias columns.
Let me explain it with an example.
In employees table, let say we need a temporary column which is the addition of job_id and department_id, we give it a name as new_random_id.
At core query, we can use HAVING clause to get data where the addition is between 10 and 15.
But when we use where, it gives a syntax error.
So, to force the query to run on WHERE clause, we have to add an extra table layer.
So add rounded bracket around the query, from SELECT to the TABLE NAME.
At the beginning, add SELECT * FROM.
After the end of rounded bracket, add any random name, which will act like a temporary table name.
And that’s it. The WHERE clause will work.
Thanks for watching. Like share and subscribe.

No comments:

Post a Comment