views:

30

answers:

1

I have 2 two tables:

organisations (id, name) 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?

+4  A: 
SELECT  o.*, m.*
FROM    (
        SELECT  *
        FROM    organizations
        ORDER BY
                id
        LIMIT 10
        ) o
LEFT JOIN
        organizationmeta m
ON      m.orgid = o.id
Quassnoi