Mysql
 sql >> Base de données >  >> RDS >> Mysql

Aide sur les requêtes SQL - avoir deux conditions where dans la condition de jointure

Convertissez-le en LEFT JOIN, puis mettez-y les conditions supplémentaires

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)