SQL Full Outer Join Using UNION For MySQL

SQL Full Outer Join Using UNION For MySQL

Ankit Bansal

2 года назад

10,773 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@sourabhredekar6208
@sourabhredekar6208 - 17.09.2023 14:09

Thanks bhai😊😊😊

Ответить
@laxmanrao9394
@laxmanrao9394 - 18.07.2023 11:26

Thanks a lot for the video
May i know the difference between union and full outer join with some example

Ответить
@NitishKumar-xr9tx
@NitishKumar-xr9tx - 18.04.2023 17:20

The child in the background will proud to watch these lectures in the Future😜

Ответить
@ammani2618
@ammani2618 - 14.03.2023 15:22

Sir can we do left join and right join then combining by union to get full outer join?

Ответить
@aniketraut6864
@aniketraut6864 - 05.02.2023 11:20

Thank you Ankit, your videos are helping me a lot to learn new things related with sql. keep doing the good work. God bless you.

Ответить
@anshulgupta1611
@anshulgupta1611 - 20.12.2022 11:01

Thanks @Ankit. This is very clear. those are looking for DDL-
--DDL Statement
Drop table Customer
Drop table Customer_order
Create Table Customer (Customer_id int, customer_name Varchar(20))
Create Table Customer_order (Customer_id int, orderDate date)

Insert into Customer Values (1,'A')
Insert into Customer Values (2,'B')
Insert into Customer Values (3,'C')
Insert into Customer Values (4,'D')
Insert into Customer Values (5,'E')

Insert into Customer_order Values (1,'2022-01-05')
Insert into Customer_order Values (2,'2022-01-06')
Insert into Customer_order Values (3,'2022-01-07')
Insert into Customer_order Values (4,'2022-01-08')
Insert into Customer_order Values (6,'2022-01-09')


Select * From Customer
Select * From Customer_order

--FULL outer JION
Select C.*,CO.*
From Customer C FULL OUTER JOIN Customer_order co
ON C.Customer_id = co.Customer_id

--UNION ALL

Select C.*,CO.*
From Customer C LEFT JOIN Customer_order CO
ON C.Customer_id = co.Customer_id
UNION ALL
Select C.*,CO.*
From Customer C RIGHT JOIN Customer_order CO
ON C.Customer_id = co.Customer_id
WHERE c.Customer_id IS NULL

--UNION only
Select *, ROW_NUMBER() over (ORDER BY countera) as counterB
From
(
Select C.Customer_id as CCustomerID,c.customer_name, CO.Customer_id as COCustomerID, Co.orderDate,ROW_NUMBER() over (ORDER BY C.Customer_id) as countera
From Customer C LEFT JOIN Customer_order CO
ON C.Customer_id = co.Customer_id
UNION
Select C.Customer_id as CCustomerID,c.customer_name, CO.Customer_id as CoCustomerID, Co.orderDate,ROW_NUMBER() over (ORDER BY CO.Customer_id) as countera
From Customer C RIGHT JOIN Customer_order CO
ON C.Customer_id = co.Customer_id
) X

Ответить
@sivasrimakurthi206
@sivasrimakurthi206 - 05.12.2022 21:14

this is 1 comprehensive video about the Window Frames class, it did explain the aggregation logic on windows, Frames etc very well. Loved the content, keep rocking @AnkitBansal 🙂

Ответить
@asthapatel2924
@asthapatel2924 - 31.10.2022 10:24

I have to join two tables is it wrong if i write table 1 union all table 2 instead of table 1 left join table 2 union all table 2 left join table 1

Ответить
@SuperMohit95
@SuperMohit95 - 17.09.2022 23:18

In MYSQL there is not separate command for full outer join. Anytime I do a full outer join I use this method!!

Ответить
@ayushishukla2333
@ayushishukla2333 - 04.08.2022 22:07

Requesting you please do a video on UNION and UNION ALL. I sometimes find it really confusing like here why did we go with union all and not union. Even tho when UNION gives us the unique entries not like UNION ALL that gives duplicates???

Ответить
@kolisettysasiram7732
@kolisettysasiram7732 - 07.06.2022 05:49

union of left join and right join also give same result right... since we use union, it will remove duplicates.. now my doubt is why you choose where condition for this question.. Any reason behind that rather than using union of right & left join ??

Ответить
@utkarshdixit3502
@utkarshdixit3502 - 05.06.2022 21:01

Very nice video, thanks!

Ответить
@saivaibhav3331
@saivaibhav3331 - 05.06.2022 06:56

Please share the script of these two tables.

Ответить
@saivaibhav3331
@saivaibhav3331 - 05.06.2022 06:51

can we do using the below code?

Select c.customer_id , c.customer_name , co.customer_id , co.order_date from customers c
Left join
Costomers_orders co
On c.customer_id = co.customer_id

Union all

Select c.customer_id , c.customer_name , co.customer_id , co.order_date from customers c
Right join
Costomers_orders co
On c.customer_id = co.customer_id;

Ответить
@navejpathan
@navejpathan - 04.06.2022 17:28

I think UNION will also give same result. So no need to use where condition if we use UNION only, because UNION will remove duplicate. Please correct me if I am wrong.

Ответить
@karangupta_DE
@karangupta_DE - 04.06.2022 15:23

Hi Ankit, could you kindly make a video and talk about EXISTS and NOT EXISTS.

Ответить
@abhishek_grd
@abhishek_grd - 03.06.2022 20:44

Ankit ! Can you share the DDL for this as well?

Ответить
@abhishek_grd
@abhishek_grd - 03.06.2022 20:43

Amazing as usual ! Thanks

Ответить
@architgarg97288
@architgarg97288 - 03.06.2022 18:52

If we use union instead of union all then we dont need to use null condition right??

Ответить
@explorer_baba2750
@explorer_baba2750 - 03.06.2022 18:48

Last week , One interviewer asked same question from me. 🙂

Ответить
@nikhilarora7549
@nikhilarora7549 - 03.06.2022 15:14

I want to calculate TTM (Trailing Twelve month Revenue), I have each quarter revenue,, time how could i calculate this TTM?

Ответить
@hackingrabi458
@hackingrabi458 - 03.06.2022 14:30

seems interesting

Ответить
@hackingrabi458
@hackingrabi458 - 03.06.2022 14:30

Seems interesting

Ответить