1
這裏有一個示例場景,比如說我有一個社交媒體網站,比如Facebook或者其他,我想根據他們的電子郵件地址獲取所有用戶的照片ID。將表格行組合成一行(Set?)
這裏是(基本型)
x_users:
- user_id
- user_email
- user_pass
x_photos:
- photo_id
- user_id
我怎樣才能使它的表,這樣的結果對於像查詢:
SELECT * FROM x_users
LEFT JOIN x_photos ON x_users.user_id = x_photos.user_id
WHERE x_users.email = '...';
將返回是這樣的:(所有的單列,至少)
+---------+------------+-------------+-------------+
| user_id | user_email | user_pass | user_photos |
+---------+------------+-------------+-------------+
| 1 | ... | my-password | 1,2,3,4,5 |
+---------+------------+-------------+-------------+
代替:
+---------+------------+-------------+----------+
| user_id | user_email | user_pass | photo_id |
+---------+------------+-------------+----------+
| 1 | ... | my-password | 1 |
| 1 | ... | my-password | 2 |
| 1 | ... | my-password | 3 |
| 1 | ... | my-password | 4 |
| 1 | ... | my-password | 5 |
+---------+------------+-------------+----------+
每天學習新花樣!太棒了。謝謝。 – Hobbyist