SQL Interview Question Based on Full Outer Join | Asked in Deloitte

  Рет қаралды 20,789

Ankit Bansal

Ankit Bansal

2 жыл бұрын

In this video we will learn how to deal with full outer joins. In full outer join we need to deal with lot of null values so it is important to understand this concept.
This question was also asked to me in Deloitte Interview way back in 2017.
Here is the ready script:
create table emp_2020
(
emp_id int,
designation varchar(20)
);
create table emp_2021
(
emp_id int,
designation varchar(20)
)
insert into emp_2020 values (1,'Trainee'), (2,'Developer'),(3,'Senior Developer'),(4,'Manager');
insert into emp_2021 values (1,'Developer'), (2,'Developer'),(3,'Manager'),(5,'Trainee');
#sql #interview #fullouterjoin #outerjoin #fulljoin

Пікірлер: 113
@wizardop2100
@wizardop2100 2 сағат бұрын
Your ability to divide complex problems into simpler ones is phenomenal. Thank you so much for the sql content. keep going
@ankitbansal6
@ankitbansal6 Сағат бұрын
Cheers
@aj-lan284
@aj-lan284 Жыл бұрын
Kya SQL coding skill hai bhai😍😍😍 Ekdm kadak
@deepthimurali962
@deepthimurali962 2 жыл бұрын
Thank you Ankit for clear explanation! Keep the videos coming :) Its super useful.
@brijendramohangupta9928
@brijendramohangupta9928 2 жыл бұрын
Loved your step-by-step approach towards solving complex SQL queries. Hope to see more similar videos in the coming days and really appreciate your hard work in making such a helpful content.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thanks bro 😊
@DreamHome_Shorts
@DreamHome_Shorts 2 жыл бұрын
great example to understand join as well as switch case.
@LS8636
@LS8636 Жыл бұрын
I really appreciate your efforts bhai. All your tutorials are very information, best SQL content on youtube.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you 😊
@DRahulRajuYadav
@DRahulRajuYadav 15 күн бұрын
Excellent Explanation!!!!
@milindzuge906
@milindzuge906 Жыл бұрын
Goldmine Content bro..!!❣
@kadamteja5743
@kadamteja5743 2 жыл бұрын
Hi sir, Really appreciate your efforts in making the things simpler to understand the complex SQL queries. A big thanks for your content on SQL. Waiting for more scenarios based questions.....Thanks!!!!!👏👏
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you for watching 🙂
@gameply347
@gameply347 29 күн бұрын
Amazing video got to learn so many things
@mohit231
@mohit231 2 жыл бұрын
Really Thankful for your content.
@abhisharma7780
@abhisharma7780 Жыл бұрын
select COALESCE (e1.emp_id, e2.emp_id), case when e2.emp_id is null then 'Resigned' when e1.emp_id is null then 'Newly joined' else 'Promoted' end as status from emp_2020 e1 full outer join emp_2021 e2 on e1.emp_id=e2.emp_id where (e1.emp_id is null or e2.emp_id is null) or (e1.designation e2.designation)
@deeptisharma90
@deeptisharma90 6 ай бұрын
i was able to write the query except using isnull for the emp_id in the very end. Proud of my persistence. Thank you for providing great informative content for free!
@ankitbansal6
@ankitbansal6 6 ай бұрын
Excellent!
@somanathking4694
@somanathking4694 2 ай бұрын
Thank you for wonderful teachings sir! I have tried this.. WITH temp AS ( SELECT e1.emp_id AS emp_id_2020, e2.emp_id AS emp_id_2021, CASE WHEN e1.designation = 'Trainee' AND e2.designation = 'Developer' OR e1.designation = 'Senior Developer' AND e2.designation = 'Manager' THEN 'promoted' WHEN e2.designation = 'Trainee' AND e1.designation IS NULL THEN 'New' END AS new_column FROM emp_2020 AS e1 FULL OUTER JOIN emp_2021 AS e2 ON e1.emp_id = e2.emp_id ) SELECT emp_id_2021,new_column FROM temp WHERE emp_id_2021 is not null and new_column is not null;
@bhavani-gy6ts
@bhavani-gy6ts 4 ай бұрын
clearly explained thank you so much ankit sir. for those who are writing in mysql... In mysql, full outer join is not available but can achieve using union. below sol is in mysql with cte as (select e1.emp_id as id1,e1.designation as d1,e2.emp_id as id2,e2.designation as d2 from emp_2022 e1 left join emp_2023 e2 on e1.emp_id=e2.emp_id union select e1.emp_id as id1,e1.designation as d1,e2.emp_id as id2,e2.designation as d2 from emp_2022 e1 right join emp_2023 e2 on e1.emp_id=e2.emp_id) select ifnull(id1,id2) as emp_id, case when d1!=d2 then 'promoted' when d2 is null then 'Resigned' else 'New Joined' end as comment from cte where ifnull(d1,'xx') != ifnull(d2,'yy');
@Moon_Rise6393
@Moon_Rise6393 Жыл бұрын
Awesome Bansal Bro 👍👍👍
@ajinkya-eigteen5144
@ajinkya-eigteen5144 2 жыл бұрын
Very Useful Thank you so much
@sauravips
@sauravips Жыл бұрын
Crisp and clear explanation. Very well explained
@ankitbansal6
@ankitbansal6 Жыл бұрын
Glad you liked it✌️
@SudhirKumar-rl4wt
@SudhirKumar-rl4wt 2 жыл бұрын
thanks for the question and solution
@priyankasrivastava3247
@priyankasrivastava3247 11 ай бұрын
love your videos
@prashantjaiswal5260
@prashantjaiswal5260 Жыл бұрын
very good and indepth video ...Thanku sir for making this available to us
@ankitbansal6
@ankitbansal6 Жыл бұрын
It's my pleasure
@jaybharat3949
@jaybharat3949 18 күн бұрын
Omg😮😮…thanks sir❤
@vandanasharma4738
@vandanasharma4738 Жыл бұрын
loved the way you are explaining. Thank you for sharing knowledge. More power to you!! . Keep guiding us. select e20.*, e21.*,coalesce(e20.emp_id, e21.emp_id) as finalid, case when e21.designation e20.designation then 'Promoted' when e21.emp_id not in (select emp_id from emp_2020) then 'New' when e20.emp_id not in (select emp_id from emp_2021) then 'Resigned' end as designation from emp_2020 e20 full outer join emp_2021 e21 on e20.emp_id = e21.emp_id where NVL(e21.designation, 'x') != NVL(e20.designation, 'y');
@ankitbansal6
@ankitbansal6 Жыл бұрын
It's my pleasure
@moyeenshaikh9915
@moyeenshaikh9915 2 жыл бұрын
still not getting why isnull is required in last statement manager was euqla to manager so it should not have come na emp id 2 one?
@vutv5742
@vutv5742 7 ай бұрын
Completed ❤
@rajorshi1000
@rajorshi1000 2 жыл бұрын
A complex problem made very easy. isnull is really very powerful as shown by you.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Yes it is very handy 😊
@sjain5
@sjain5 Жыл бұрын
This channel is Goldmine
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you 😊
@ahsan_habib_sunny
@ahsan_habib_sunny 2 жыл бұрын
we also can join the two table on emp_id and filter based on designation: select coalesce(a.emp_id,b.emp_id), case when a.designation b.designation then 'Promoted' when a.designation is not NULL and b.designation is NULL then 'Resigned' else 'New' end as Comment from emp_2020 a full join emp_2021 b on a.emp_id = b.emp_id where a.designation b.designation or a.designation is null or b.designation is null
@Alexpudow
@Alexpudow 6 ай бұрын
Hi Ankit, good explanation thanks a lot. I have my own one. with a as ( select designation, rank() over(order by emp_id desc) ernk from emp_2020), b as ( select a.emp_id, a.designation, a1.ernk from emp_2021 a join a a1 on a.designation = a1.designation), c as ( select a.emp_id, a.designation, a1.ernk from emp_2020 a join a a1 on a.designation = a1.designation) select case when c.emp_id is null then b.emp_id when b.emp_id is null then c.emp_id else c.emp_id end emp_id ,case when c.ernk is null then 'new' when c.ernk>b.ernk then 'promoted' when c.ernk=b.ernk then 'same' else 'resigned' end comment from c full join b on c.emp_id=b.emp_id order by 1
@meghnasoni
@meghnasoni Жыл бұрын
I tried solving it this way, however Ankit's approach is obviously far better: SELECT *, case when e20.designation = e21.designation then 'same' when e21.designation is null then 'resigned' when e20.designation e21.designation then 'promoted' when e20.designation is null then 'New Joinee' end as flag from emp_2020 e20 full join emp_2021 e21 on e20.emp_id=e21.emp_id In the real world , promoted case statement logic will not work as people can be demoted, moved to different departments and we'd have to write separate logic for those cases
@chaitanyasalagala1661
@chaitanyasalagala1661 Жыл бұрын
can't we do union instead of using is null?
@BHS0668
@BHS0668 2 жыл бұрын
Great video 👍
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you 😊
@innominatesoloist1597
@innominatesoloist1597 Жыл бұрын
brilliant
@anishchhabra6085
@anishchhabra6085 6 ай бұрын
I solved this question using 2 case-when statements, can you let me know if this is a good approach or not? with cte as ( select e20.emp_id as e20_emp_id,e21.emp_id as e21_emp_id, case when e21.emp_id = e20.emp_id and e21.designation e20.designation then 'Promoted' when e21.emp_id not in (select distinct emp_id from emp_2020) then 'New' when e20.emp_id not in (select distinct emp_id from emp_2021) then 'Resigned' else 'NA' end as pos from emp_2020 e20 cross join emp_2021 e21 ) select distinct case when pos = 'New' then e21_emp_id when pos = 'Resigned' then e20_emp_id else e20_emp_id end as emp_id, pos from cte where pos 'NA' order by emp_id asc;
@dikshachourasiya5561
@dikshachourasiya5561 10 ай бұрын
Very nice
@ankitbansal6
@ankitbansal6 10 ай бұрын
Thanks
@codinguniverse9716
@codinguniverse9716 Жыл бұрын
AWESOME BRO
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thanks 🤗
@vijaypalmanit
@vijaypalmanit 2 жыл бұрын
Bhai bhai bhai ♥️
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Aree bhai 🙂
@alex45688
@alex45688 Жыл бұрын
wow awesome
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thanks 🤗
@abhishek_grd
@abhishek_grd 2 жыл бұрын
@Ankit, earlier i was able to switch to the quality of the videos now looks like it was either disabled or saying unavailable. Can you have a look at it.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Abhishek I am able to switch to HD .. not sure what could be the issue with your system
@Mysingh9767
@Mysingh9767 2 жыл бұрын
Thanks...
@ankitbansal6
@ankitbansal6 2 жыл бұрын
You're welcome!
@florincopaci6821
@florincopaci6821 2 жыл бұрын
All your problems are good and useful not only this!
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you. I got the solution for bus passenger but it is bit complex. I am on it to find a simpler solution.
@florincopaci6821
@florincopaci6821 2 жыл бұрын
@@ankitbansal6 You welcome! I learned a lot from you ,from your videos and only if is possible to help with that problem! Thank you for all the videos! In this way every trainee in the companies should explain Sql but unfortunately is not happened like this. I hope you will find a solution to that problem! All the best! and good luck!
@ShivaKumarTeam
@ShivaKumarTeam Жыл бұрын
in the above video first part, we have used "is null" and "isnull"- what is the dif between "is null" and "isnull", is both are same? how to identify which one to use and when to use?
@ManpreetSingh-tv3rw
@ManpreetSingh-tv3rw Жыл бұрын
isnull is a function which requires 2 arguments , is null is an operator.
@SaurabhHiteshbhaiBhoi
@SaurabhHiteshbhaiBhoi 3 ай бұрын
I am unable to do full outer join in MySQL and I have already tried union of left and right join but the result I got is not same as yours what should I do?
@ankitbansal6
@ankitbansal6 3 ай бұрын
kzbin.info/www/bejne/kHfbdJquiJaVbbs
@prajjwaljaiswal3419
@prajjwaljaiswal3419 2 жыл бұрын
In MySQL workbench Full outer join doesn't work. Using (left + right) but getting stuck. Any alternate solution without using full outer join?
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Check this out kzbin.info/www/bejne/kHfbdJquiJaVbbs
@mohammadabdullahansari6314
@mohammadabdullahansari6314 Жыл бұрын
Check my query: select e1.emp_id, case when e1.designation != e2.designation then 'Promoted' when e1.designation is null then 'New' else 'Resigned' end as comment from emp_2020 e1 left join emp_2021 e2 on e1.emp_id = e2.emp_id where ifnull(e1.designation,'xxx') != ifnull(e2.designation,'yyy') union select e2.emp_id, case when e1.designation != e2.designation then 'Promoted' when e1.designation is null then 'New' else 'Resigned' end as comment from emp_2020 e1 right join emp_2021 e2 on e1.emp_id = e2.emp_id where ifnull(e1.designation,'xxx') != ifnull(e2.designation,'yyy')
@iamsatyadeep
@iamsatyadeep 2 жыл бұрын
Hi Ankit, while comparing designations in case statement, how can we compare 'null' designation with designation having some values?
@ankitbansal6
@ankitbansal6 2 жыл бұрын
You can do null handling using isnull or coalesce function . By giving some default value you can compare with not null values
@iamsatyadeep
@iamsatyadeep 2 жыл бұрын
@@ankitbansal6 true. But in your query in case statement you haven't handled null values still the output was correct, how? Also in joining condition if we haven't put null handling the row was getting dropped then why it's happening in case statement? I hope you get my question.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
@@iamsatyadeep in case statement it is going into else condition.
@Buzzingfact
@Buzzingfact 2 жыл бұрын
Nice video.. but can you create videos on store procedure use cases in data transformation/real scenarios as this is very less available in youtube.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Okay
@sumanacharya461
@sumanacharya461 Жыл бұрын
I actually tried the question before watching the video , so my solution I think is bit messy select (case when emp1=emp2 then emp1 when emp1 is NULL then emp2 else emp1 end), (case when des1 is NULL then 'New' when des2 is NULL then 'Resigned' else 'Promoted' end) from (select e20.emp_id as emp1,e21.emp_id as emp2, e20.designation as des1 ,e21.designation as des2 from emp_2020 as e20 full outer join emp_2021 as e21 on e20.emp_id = e21.emp_id where e20.designation is NULL or e21.designation is NULL or e20.designation != e21.designation)
@uttamthakur2016
@uttamthakur2016 8 ай бұрын
Any videos where you Explained where clause and ON clause difference , Please let me know the link , I need to understand .
@ankitbansal6
@ankitbansal6 8 ай бұрын
kzbin.info/www/bejne/j6Hal6RrqbOqY5Y
@parth_pm16
@parth_pm16 11 ай бұрын
I've got a lengthy solution, but after seeing your query, today I got to know a new thing which is "isnull" as a function. My sloution: with cte as( select emp_2020.emp_id as id_20, emp_2021.emp_id as id_21 ,case when emp_2020.designation!=emp_2021.designation then 'Promoted' when emp_2021.emp_id is null then 'Resigned' when emp_2020.emp_id is null then 'Traniee' end as designation1 from emp_2020 full outer join emp_2021 on emp_2020.emp_id = emp_2021.emp_id) select id_20 as emp_id,designation1 from cte where id_20 is not null and designation1 is not null union select id_21 as emp_id,designation1 from cte where id_21 is not null and designation1 is not null
@reshabsharma5711
@reshabsharma5711 11 ай бұрын
with cte is not working in my case
@parth_pm16
@parth_pm16 11 ай бұрын
@@reshabsharma5711 What error you facing?
@reshabsharma5711
@reshabsharma5711 11 ай бұрын
not exactly error, I think cte doesn't work in postgress@@parth_pm16
@parth_pm16
@parth_pm16 10 ай бұрын
@@reshabsharma5711 Thank you for your response!
@ManpreetSingh-tv3rw
@ManpreetSingh-tv3rw Жыл бұрын
Solved a similar question on Leetcode using above concept. Write an SQL query to report the IDs of all the employees with missing information. The information of an employee is missing if: The employee's name is missing, or The employee's salary is missing. select isnull(e.employee_id,s.employee_id) as employee_id from employees e full outer join salaries s on e.employee_id = s.employee_id where e.name is NULL or s.salary is null order by employee_id
@UnrealAdi
@UnrealAdi Жыл бұрын
Tried in MySQL: select *, case when e.designation != e1.designation then 'Promoted' when e.designation = e1.designation then 'No Change' when e.emp_id is null then 'New Joinee' when e1.emp_id is null then 'Resigned' end stat from emp_2020 e left join emp_2021 e1 on e.emp_id = e1.emp_id where e.designation != e1.designation or e1.emp_id is null union select *, case when e.designation != e1.designation then 'Promoted' when e.designation = e1.designation then 'No Change' when e.emp_id is null then 'New Joinee' when e1.emp_id is null then 'Resigned' end stat from emp_2020 e right join emp_2021 e1 on e.emp_id = e1.emp_id where e.designation != e1.designation or e.emp_id is null ; Please, feel free to optimize the query. Also, excellent work Ankit! Kudos!
@akshayjoshi4106
@akshayjoshi4106 Жыл бұрын
Hi Ankit, full outer join not giving same results as in oracle sql . Any idea
@tiyashachakraborty7512
@tiyashachakraborty7512 7 ай бұрын
Do left join twice and then use Union all
@ratneshraj4653
@ratneshraj4653 2 жыл бұрын
What if here we also had to check for demotions .. assuming few candidate were demoted?
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thats the assignment for you
@narenkrishh7412
@narenkrishh7412 2 жыл бұрын
Hi brother! All your videos are nice and refreshing my basics. Currently I am working as SQL developer developing reports for fintech AMC companies for past two years. What can I learn to progress more in this domain. Some are saying snowflake some are saying Hadoop spark and also some with plsql..I am very much confused with what to chose and study. Pls suggest me a good career path.. Thanks in advance!
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Don't think too much. Pick one and learn it. There are opportunities in all technologies. Hadoop spark or snowflake or AWS or GCP or azure. Pick any one whichever you find interesting.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
If you are into reporting you can choose BI or Data analyst path . Learn tableau or powe bi
@abhishek_grd
@abhishek_grd 2 жыл бұрын
And what if the employee gets demoted. How to handle then ??
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Then we need to have some hierarchy so we can identify if it is promotion or demotivate. Based on that we can change case when.
@shyamshivakumar7807
@shyamshivakumar7807 2 жыл бұрын
with cte as ( select * ,'2020' as year_status from emp_2020 union all select * ,'2021' as year_status from emp_2021 order by emp_id asc ) ,cte1 as ( select * ,row_number() over(partition by emp_id) as rnk from cte order by emp_id asc,rnk desc ) select emp_id ,case when count(distinct designation)='2' and rnk='2' then 'Promoted' when count(distinct designation)='1' and rnk='2' then 'Same Designation' when rnk='1' and year_status='2020' then 'Resigned' when rnk='1' and year_status='2021' then 'New_Joiner' end as emp_status from cte1 group by emp_id Different method but not optimized query... Hope it is easy to understand and this will work in all input cases..
@Venom-yk3wu
@Venom-yk3wu Жыл бұрын
is fulljoin n full oter the same ?
@ankitbansal6
@ankitbansal6 Жыл бұрын
Yes
@mradulgupta
@mradulgupta 8 ай бұрын
select a.emp_id,a.comment from (select coalesce(a.emp_id,b.emp_id) emp_id,a.designation as prev_designation,b.designation as curr_designation, case when b.designation is null then 'Resigned' when a.designation!=b.designation then 'Promoted' when a.designation is null then 'New' end as comment from emp_2020 a full outer join emp_2021 b on a.emp_id=b.emp_id) a where a.comment is not null
@ujjwalvarshney3188
@ujjwalvarshney3188 Жыл бұрын
select nvl(a.emp_id,b.emp_id) ,Case when a.designation = b.designation then 'Not Promoter' when a.designation is null then 'New Employee' when b.designation is null then 'Resigned' else 'Promoted' end as Comment from emp_2020 a full join emp_2021 b on a.emp_id = b.emp_id order by 1;
@NitishKumar-xr9tx
@NitishKumar-xr9tx 4 ай бұрын
MySQL Solution: with cte as( select e1.emp_id id_2020, e1.designation des_2020, e2.emp_id id_2021, e2.designation des_2021 from emp_2020 e1 Left JOIN emp_2021 e2 on e1.emp_id = e2.emp_id UNION select e1.emp_id id_2020, e1.designation des_2020, e2.emp_id id_2021, e2.designation des_2021 from emp_2020 e1 Right JOIN emp_2021 e2 on e1.emp_id = e2.emp_id ) select case when id_2020 is Not Null then id_2020 else id_2021 end as emp_id, case when des_2020 is NULL then 'new' when des_2021 is NULL then 'resigned' when des_2020 des_2021 then 'promoted' end as new_des from cte where des_2020 des_2021 or des_2020 is NULL or des_2021 is NULL;
@RIKKY988
@RIKKY988 2 жыл бұрын
Your voice quality is not good bro .pls change your microphone
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thanks for pointing out. I will check.
@dip_agr
@dip_agr Жыл бұрын
@ankitbansal6 brother In mysql workbench, its succesfully running the following code but also resulting that developer column which was same, which was suppose to be removed right, can you please help me with it. select * from emp_2020; select * from emp_2021; select e20.*, e21.* from emp_2020 e20 left join emp_2021 e21 on e20.emp_id=e21.emp_id union select * from emp_2020 e20 right join emp_2021 e21 on e20.emp_id=e21.emp_id where coalesce(e20.designation,'xxx') != coalesce(e21.designation,'yyy')
@imnishantm
@imnishantm Жыл бұрын
select * from (select isnull(e1.emp_id,e2.emp_id) as emp_id, case when e1.designation!=e2.designation then 'Promoted' when e1.designation is null then 'New' when e2.designation is null then 'Resigned' end as Comment from emp_2020 e1 full outer join emp_2021 e2 on e1.emp_id=e2.emp_id)t where Comment is not null
@grim_rreaperr
@grim_rreaperr Жыл бұрын
WITH CTE AS ( SELECT COALESCE(e1.emp_id, e2.emp_id) AS emp_id, e1.designation AS initial, e2.designation AS final FROM emp_2020 AS e1 FULL OUTER JOIN emp_2021 AS e2 ON e1.emp_id = e2.emp_id ) SELECT emp_id, initial,final, (CASE WHEN initial = final THEN 'same' WHEN initial IS NULL THEN 'New' WHEN final IS NULL THEN 'Resigned' ELSE 'Promoted' END) AS status FROM CTE
@umakantkhandekar5748
@umakantkhandekar5748 2 жыл бұрын
with c as( select n.emp_id new_emp_id ,n.designation new_design, o.emp_id old_id,o.designation old_desig from emp_2021 n full outer join emp_2020 o on n.emp_id=o.emp_id ) select new_emp_id,'Promoted' from c where isnull(new_design,'')!=isnull(old_desig,'') and new_design is not null and old_desig is not null union select old_id,'Resigned' from c where new_design is null and old_desig is not null union select new_emp_id,'new' from c where new_design is not null and old_desig is null
@kartikpidurkar9590
@kartikpidurkar9590 Жыл бұрын
MySQL Solution: with cte as( select e1.emp_id,e1.designation as 'D1',e2.designation as 'D2' from emp_2020 e1 left join emp_2021 e2 on e1.emp_id=e2.emp_id UNION select e2.emp_id,e1.designation,e2.designation from emp_2020 e1 RIGHT join emp_2021 e2 on e1.emp_id=e2.emp_id) select emp_id, CASE WHEN D2 IS NULL THEN 'Resigned' WHEN D1=D2 THEN 'NO_Promotion' WHEN D1 IS NULL THEN 'New_Joinee' ELSE 'PROMOTED' END AS 'STATUS' FROM cte;
@subhojitchatterjee6312
@subhojitchatterjee6312 Жыл бұрын
Solution using MySql. The isnull trick didn't click so I went the long route!!! WITH CTE AS ( SELECT T1.EMP_ID AS E1,T1.DESIGNATION AS D1,T2.EMP_ID AS E2,T2.DESIGNATION AS D2 FROM emp_2020 T1 LEFT JOIN emp_2021 T2 ON T1.EMP_ID=T2.EMP_ID), CTE_2 AS ( SELECT T1.EMP_ID AS E1,T1.DESIGNATION AS D1,T2.EMP_ID AS E2,T2.DESIGNATION AS D2 FROM emp_2020 T1 RIGHT JOIN emp_2021 T2 ON T1.EMP_ID=T2.EMP_ID) SELECT * FROM (SELECT E1 AS EMP_ID ,CASE WHEN D1D2 THEN "PROMOTED" WHEN D2 IS NULL THEN "RESIGNED" END AS STATUS FROM CTE UNION SELECT E2 AS EMP_ID,CASE WHEN E1 IS NULL THEN "NEW" END AS STATUS FROM CTE_2) T1 WHERE STATUS IS NOT NULL;
All About SQL Aggregations | SQL Advance | Zero to Hero
17:43
Ankit Bansal
Рет қаралды 50 М.
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 14 МЛН
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 45 МЛН
Most Asked SQL Interview Question - Solved Using 3 Methods
14:51
Rishabh Mishra
Рет қаралды 68 М.
Deloitte SQL Interview Questions and Answers
17:09
Training2SQL MSBI
Рет қаралды 141 М.
Как удвоить напряжение? #электроника #умножитель
1:00
Hi Dev! – Электроника
Рет қаралды 1,1 МЛН
Look, this is the 97th generation of the phone?
0:13
Edcers
Рет қаралды 7 МЛН
Tag him😳💕 #miniphone #iphone #samsung #smartphone #fy
0:11
Pockify™
Рет қаралды 2,2 МЛН
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 17 МЛН
#samsung #retrophone #nostalgia #x100
0:14
mobijunk
Рет қаралды 13 МЛН