Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Ajuda da consulta SQL - tem duas condições where na condição de junção


Converta-o para LEFT JOIN e coloque a(s) condição(ões) adicional(is) lá
SELECT DISTINCT d.Name, t.Buyer, t.Seller FROM  Book AS b
  LEFT JOIN TradingDesk AS d  ON b.TradingDeskId = d.Id
    LEFT Join Trade as t 
       on  substring(t.Seller,2,len(t.Seller)) = cast(b.Id as varchar)

       AND t.Seller like 'B%' -- put your additional condition(s) here

UNION
SELECT DISTINCT d.Name , t.Buyer, t.Seller FROM  Book AS b 
  LEFT JOIN TradingDesk AS d ON b.TradingDeskId = d.Id
    LEFT Join Trade as t 
       on substring(t.Buyer,2,len(t.Buyer)) = cast(b.Id as varchar)