我有如下查询:
SELECT
c.id,
c.user,
c1.user,
c2.user
FROM (
SELECT
id,
user
FROM
table_x
) c
INNER JOIN table_x c1 ON c.id = c1_id AND c.user = 'steve'
INNER JOIN table_x c2 ON c.id = c2.id AND c1.user = 'rob'
INNER JOIN table_x c3 ON c.id = c3.id AND c2.user LIKE 'r%'
GROUP BY c.id, c.user, c1.user, c2.user
它可以产生如下结果集:
id | user | user | user
1 steve rob rob52
1 steve rob rob
我需要结果集不包括跨两列的用户不唯一的第二行。有没有办法在不使用 where 子句检查每个单独的列组合的情况下检查这一点?因为当结果集跨越到 6 列时,检查起来就太多了。
结果集也有可能返回为:
id | user | user | user
1 rob steve rob
因此,在连接时与<>
or!=
运算符进行比较不会捕获这样的行,但可以捕获上述结果集中的第 2 行。
谢谢