Good evening, there is a problem that I can’t solve. There are 3 tables:
- tm_posts - data about posts and pages
- tm_attributes - data on tags and categories
- tm_relationships - links 1 and 2 tables
Example structure:
tm_posts: id | name | text ------------------- 1 | kols | <ТЕКСТ> 2 | ando | <ТЕКСТ> 3 | krot | <ТЕКСТ> tm_attributes: id | sign | attr_name ------------------- 1 | tag | учебник 2 | tag | дождь 3 | cat | личное 4 | cat | опыт tm_relationships: id | id_attr | id_post ------------------- 1 | 1 | 2 2 | 2 | 2 3 | 3 | 2 4 | 4 | 2 I need to get this result by nick ando:
id | name | text | tags | category | ----------------------------------------------------- 2 | ando | <ТЕКСТ> | учебник,дождь | личное,опыт | Those. data from tm_posts table is taken by nick ando, a bunch of tags and categories are searched for by post id in tm_relationships table. Then we get the data from the tm_attributes table. This data is merged into a string.
That's what happened to do:
SELECT t1.*, GROUP_CONCAT(t3.attr_name) As `tags` FROM tm_posts t1 JOIN tm_relationships t2 ON t1.id = t2.id_post JOIN tm_attributes t3 ON t3.id = t2.id_attr WHERE t1.name= 'ando' AND t3.sign = 'tag' GROUP BY t1.id This code displays everything except categories. How do I add more categories here.
----------------------------- Added:
It is necessary to select all the records from the database with the category "personal", but at the same time, for each record you need to paste a column with a bunch of tags.
The structure of the tables remains the same. The result should produce something like this:
id | name | text | tags | category | ---------------------------------------------------------------------- 2 | ando | <ТЕКСТ> | учебник,дождь | личное | 5 | ник | <ТЕКСТ> | какие-то теги | личное | 6 | ник | <ТЕКСТ> | какие-то теги | личное | Those. selected all entries with tags, but only with a certain category of "personal"