With the following posts and metas data table
metas
+------+-----------+----------+
| id | name | type |
+------+-----------+----------+
| 1 | news | category |
| 2 | sports | tag |
| 3 | music | category |
+------+-----------+----------+
posts
+------+-----------+
| id | title |
+------+-----------+
| 1 | aaaaa |
| 2 | bbbbb |
| 3 | ccc |
+------+-----------+
posts_metas
+------------+--------------+
| posts_id | metas_id |
+------------+--------------+
| 1 | 1 |
| 1 | 3 |
| 1 | 2 |
+------------+--------------+
How to retrieve the metas with type="category"
of the post with id=1
? the result will almost be like this:
+------------+-----------+-----------+----------+
| posts_id | metas_id | name | type |
+------------+-----------+-----------+----------+
| 1 | 1 | news | category |
| 1 | 3 | music | category |
+------------+-----------+-----------+----------+