+----+-------+---------+------+--------+--------+
|q_id|q_title|q_content|q_date|q_status|q_author|
+----+-------+---------+------+--------+--------+
| 1 |varchar| text | int | int | int |
+----+-------+---------+------+--------+--------+
This is the first table: questions.
Tags table has this structure:
+------+--------+---------------+
|tag_id|tag_name|tag_description|
+------+--------+---------------+
| int |varchar | text |
+------+--------+---------------+
And the third table (question_tags) has this structure:
+----+--------+------+
| id | tag_id | q_id |
+----+--------+------+
|int | int | int |
+----+--------+------+
The last table (users) has this structure:
+----+----------+--------+
| id | username |password|
+----+----------+--------+
|int | varchar |varchar |
+----+----------+--------+
I used to select the data with this query:
SELECT * , GROUP_CONCAT( tags.tag_name )
FROM questions
LEFT JOIN users
ON q_author = users.id
LEFT JOIN question_tags
ON questions.q_id = question_tags.q_id
LEFT JOIN tags ON tags.tag_id = question_tags.tag_id
GROUP BY questions.q_id
But it doesn’t satisfy my needs anymore. Also please notice that in the question_tags table you can have more than one tag per question and I want to get all tags and their IDs.
The query is correct. If you want the IDs of tags:
How do you want the output to look?