[英]mysql multiple INNER JOIN to add two table columns to another table
three tables 三张桌子
status : ID,member_1,member_2 --> 状态:ID,member_1,member_2->
(eg. 12, member_Joseph, member_John ;
22, member_Jacob, member_Jarrod ;
31, member_Jarrod, member_John
11, member_John, member_Jacob)
submit : ID,student --> 提交:ID,学生->
(eg. 12, Amy ;
22, Brian;
31 Susan ;
11 Kyle)
info : member_name, contact --> 信息:会员名,联系->
(eg. member_Joseph, joseph@name.name;
member_Jacob, jacob@name.name ;
member_Jarrod, jarrod@name.name ;
member_John, john@name.name )
New table to build from query: 从查询建立新表:
member_Joseph, joseph@name.name, Amy;
member_Jacob, jacob@name.name, Kyle ;
member_Jarrod, jarrod@name.name, Brian, Susan ;
member_John, john@name.name, Amy, Susan, Kyle )
I'd like to make arrays of all students assigned to each member in status table 我想在状态表中排列分配给每个成员的所有学生的数组
eg. 例如。
array1 --> member_Joseph: student 1, student 2, student 3 array1-> member_Joseph:学生1,学生2,学生3
array2 --> member_John: student 2, student 4, student 5 array2-> member_John:学生2,学生4,学生5
array3 -->member_Jacob: student 3, student 5, student 1 array3->成员_雅各布:学生3,学生5,学生1
Would that be: 会是:
$query = db_query("
SELECT info.member_name, submit.student
FROM {info}
INNER JOIN {status}
ON info.member_name = status.member_1
INNER JOIN {status}
ON info.member_name = status.member_2
INNER JOIN {submit}
ON submit.id = status.id
");
while($result = db_fetch_array($query)){
echo $result['student']; //iterate through members and print students for each
}
The error is: "Not unique table/alias" 错误是:“不是唯一的表/别名”
(fyi: I'm using Drupal 6 syntax) (仅供参考:我正在使用Drupal 6语法)
I think it should be the table info
should be joined twice so you can get the member_name of each memberID. 我认为应该将表info
连接两次,以便您可以获取每个memberID的member_name。 You also need to supply an alias for the table so they can be uniquely identified, eg 您还需要为表提供别名,以便可以唯一地标识它们,例如
SELECT a.*,
b.member_name memberName1,
c.member_name memberName2,
// other columns you might want to show
FROM status a
INNER JOIN info b
ON a.member_1 = b.member_name
INNER JOIN info c
ON a.member_2 = c.member_name
INNER JOIN submit d
ON a.ID = d.ID
To further gain more knowledge about joins, kindly visit the link below: 要进一步获得有关联接的知识,请访问以下链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.