什么是正确的 MySQL 查询?这就是我想要实现的目标。
- 我想显示所有状态更新条目、发布日期、发布者用户名、性别、城市和标签
- 我想显示 user_id='1' 的成员的所有状态更新条目、状态更新发布的日期、发布者用户名、性别、城市和成员在其个人资料中的标签
- 以及如何在一行中显示用户在其个人资料中的所有标签,并用“,”分隔?我之前尝试过 group_concat ,但我无法让它工作。请帮忙。
这是我的桌子
STATUS_UPDATE Table
+------------------------------------------------------+
| status_id | user_id | body | postdate |
+-----------+---------+-----------------+--------------+
| 1 | 1 | hello world | Aug 12, 2012 |
+-----------+---------+-----------------+--------------+
| 2 | 1 | i miss you | Aug 13, 2012 |
+-----------+---------+-----------------+--------------+
| 3 | 2 | lorem ipsum | Aug 14, 2012 |
+-----------+---------+-----------------+--------------+
| 4 | 2 | why me? why? | Aug 14, 2012 |
+-----------+---------+-----------------+--------------+
MEMBERS Table //Primary data of members
+---------------------------------------------------+
| user_id | username | password | email |
+---------+----------+------------+-----------------+
| 1 | john_doe | qwerty | john@doe.com |
+---------+----------+------------+-----------------+
| 2 | maryjane | pass123 | mary@jane.com |
+---------+----------+------------+-----------------+
MEMBERS_DATA Table //Profile Fields
+----------------------------------------------+
| user_id | gender | description | city |
+---------+--------+---------------+-----------+
| 1 | male | i am simple | chicago |
+---------+--------+---------------+-----------+
| 2 | female | i am flirty | newyork |
+---------+--------+---------------+-----------+
MEMBERS_TAGS Table //tags that members added to their profiles
+-------------------+
| user_id | item_id |
+---------+---------+
| 1 | 555 |
+---------+---------+
| 1 | 666 |
+---------+---------+
| 1 | 7777 |
+---------+---------+
| 2 | 8888 |
+---------+---------+
TAGS Table //the info of the tags
+------------------------------+
| item_id | cat_id | name |
+---------+--------+-----------+
| 555 | 5 | sexy |
+---------+--------+-----------+
| 666 | 5 | beauty |
+---------+--------+-----------+
| 7777 | 6 | music |
+---------+--------+-----------+
| 8888 | 6 | movies |
+---------+--------+-----------+
CATEGORY Table //the category of the tags
+-------------------------+
| cat_id | category_name |
+---------+---------------+
| 5 | appearance |
+---------+---------------+
| 6 | hobbies |
+---------+---------------+
顺便说一句,我正在使用 PHP 进行编码,我要提前感谢您的帮助。