Home > Mobile >  Sub query in join with 3rd table
Sub query in join with 3rd table

Time:03-16

My Current Join Query

select c.email
       , c.name
       , o.created
       , o.customerId
       , o.code as order_code
       , o.totalValue
       ,'cash' as description
       , o.WalletCash as amount 
from   Order o join Customer c  on o.customerId = c.id 
where  o.WalletCash > 0 
and    o.created BETWEEN '2022-03-16' AND '2022-03-16' 

I want to make join or sub query with below query

select customerId from   CustomerWallet where  customerId =100

The Customer, CustomerWalletand Order tables are all associated by CustomerID.

How join 3rd table in join query in mysql?

CodePudding user response:

You can alias the first query and use that with the second table.

select * from (select c.email
       , c.name
       , o.created
       , o.customerId
       , o.code as order_code
       , o.totalValue
       ,'cash' as description
       , o.WalletCash as amount 
from   Order o join Customer c  on o.customerId = c.id 
where  o.WalletCash > 0 
and    o.created BETWEEN '2022-03-16' AND '2022-03-16') tab t join CustomerWallet c on t.order_code = c.order_code and c.order_code = like "           
  • Related