[英]SQL query and join table
I am given an array of group IDs. 我得到了一组组ID。
I have a table that has these integer fields: 我有一个包含这些整数字段的表:
id, node_id and group_id
In this table, node_id
is not unique and group_id
is not unique. 在此表中,
node_id
不是唯一的,而group_id
不是唯一的。
I need to locate each unique nodeID
that has all of the given groupIDs
. 我需要找到具有所有给定
groupIDs
每个唯一的nodeID
。 (I want just one instance of each node_id
.) (我只需要每个
node_id
一个实例。)
//????
$groups_str = implode(',', $groups);
$query = "SELECT node_id FROM group_nodes
WHERE ............ IN({$groups})
...........";
SELECT node_id
FROM group_nodes
WHERE group_id IN ($groups)
group by node_id
having count(distinct group_id) = $arraySize
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.