开发者

mysql pagination with multiple tables

开发者 https://www.devze.com 2023-01-05 09:34 出处:网络
I have 2 two tables: organisations (id, name) 开发者_JS百科organisationsmeta (id, orgId, metaKey, metaValue)

I have 2 two tables:

organisations (id, name) 开发者_JS百科organisationsmeta (id, orgId, metaKey, metaValue)

Each organisation can have multiple associated meta rows. I'm using a Left Join right now since there can be organisations without any meta data.

How do I construct the query to fetch 10 organisations (with all associated meta data), regardless of how much metadata each organisation have?


SELECT  o.*, m.*
FROM    (
        SELECT  *
        FROM    organizations
        ORDER BY
                id
        LIMIT 10
        ) o
LEFT JOIN
        organizationmeta m
ON      m.orgid = o.id
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号