我有 2 个表,无法让我的 MySQL 查询工作:
First Table users:
user_id name
------------
1 Bob
2 Alice
Second Table fields:
id unser_id field_id value
-----------------------------
1 1 4 foo
2 1 5 10
3 2 4 bar
现在我想以一种输出的方式加入表格:
[0] => (
[user_id] => 1
[name] => Bob
[fields] => (
[4] => foo
[5] => 10
)
[1] => (
[user_id] => 2
[name] => Alice
[fields] => (
[4] => bar
)
)
非常感谢!
我试过了:
SELECT u.user_id,
u.name
FROM users as u
INNER JOIN fields as f on u.user_id = d.user_id
但我为每个用户获得的只是第一个字段条目。