Join table with MAX value from another

后端 未结 2 1525
说谎
说谎 2021-01-27 04:17
select * from order
-------------------
|orderID|productID|
-------------------
|  1    |  234    |
|  2    |  234    |
|  3    |  123    |
-------------------

select *         


        
2条回答
  •  遇见更好的自我
    2021-01-27 05:07

    when you need to use aggregate you must use group by and in compare condtion use Having

     SELECT orderID, productID, MAX(cost_price)
     FROM order LEFT JOIN product_supplier 
     ON order.productID=product_supplier.productID having cost_price=MAX(cost_price) group by productID ;
    

提交回复
热议问题