Mysql
 sql >> Database >  >> RDS >> Mysql

Guida alle query SQL:sono disponibili due condizioni in cui sono presenti condizioni di join

Convertilo in LEFT JOIN, quindi inserisci le condizioni aggiuntive 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)