2016年1月13日 星期三



一對多的table, 如何只捉,多的那邊,其中一筆呢?

原來有下面寫法

select * from users join widgets on widgets.id = (
    select id from widgets
    where widgets.user_id = users.id
    order by created_at desc
    limit 1
)

還有其他方法
Ref : https://www.periscopedata.com/blog/4-ways-to-join-only-the-first-row-in-sql.html

0 意見: