How to use sub-query in mysql JOIN function ?

mysql-tutorials

How to use SUB QUERY in mySQL Join ?

 

In the below example, they having two tables one is SKU and another is ztmpBulkInsert.

They are using ztmpBulkInsert table as sub query table and they are joining the table with master table column & secondary column example

select s.skuCode, s.skuName, IFNULL(s.stock, 0) as POSStock, IFNULL(z1.stock, 0) PhysicalStock, ‘Stock Mismatch’ Remark from sku s
left join (
select
count(*) as stock, z.skuCode
from
ztmpBulkInsert z
group by z.skuCode
) z1 on z1.skuCode = s.skuCode or z1.skuCode = s.skuCodePos
where (IFNULL(s.stock, 0) <> IFNULL(z1.stock, 0))

 

 

Related posts

Leave a Comment