Mysql Select 1:n
- by clinisbut
Hello, I have two tables that relates 1:n
content
---------
- id
- title
- text
content_meta
-------------
- id
- content_id
- meta_key
- meta_value
A content can have multiple content_meta registers associated to it. Typically content_meta will contain the category, tags, descriptions and all that stuff, so I really don't know the number of registers a content will have.
What I want to accomplish is to take the content register and also all the related registers in content_meta in a single query.
I've tried the subselect approachment but seems that I can only get one register/column (¿?)
SELECT content.*, (
SELECT *
FROM content_meta
WHERE content_id = content.id
)
FROM content
This query complains that "Operand should contain 1 column(s)", so changing the '*' by for example meta_key clears the error, but returns a NULL for this subselect...
SELECT content.*, (
SELECT meta_key
FROM content_meta
WHERE content_id = content.id
)
FROM content
Can anybody show me where to go from here please?