Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL-Abfragehilfe - zwei Where-Bedingungen in der Join-Bedingung haben

Konvertieren Sie es in LEFT JOIN und fügen Sie dann die zusätzliche(n) Bedingung(en) dort ein

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)