mysql subquery inside a LEFT JOIN

前端 未结 2 1900
遇见更好的自我
遇见更好的自我 2021-02-12 21:44

I have a query that needs the most recent record from a secondary table called tbl_emails_sent.

That table holds all the emails sent to clients. And most c

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-12 21:58

    Would this not work?

    SELECT t1.datesent,t1.customerid,t2.email,t2.name
    FROM
    (SELECT max(datesent) AS datesent,customerid
    FROM `tbl_emails_sent`
    ) as t1
    INNER JOIN `tbl_customers` as t2
    ON t1.customerid=t2.customerid
    

    Only issue you have then is what if two datesents are the same, what is the deciding factor in which one gets picked?

提交回复
热议问题