在数据库表中选择相似的行

时间:2016-03-04 09:11:32

标签: php mysql

这是我有的mysql表数据  enter image description here
在上表中我想运行一个查询

SELECT one  WHERE two=2 AS F1 AND two WHERE one=2 AS F2
SELECT one WHERE two=1 AS M1 AND two WHERE one=1 AS M2

所以,当我加入F1 and M1F2 and M2时,它只会选择与两个WHERE one = 1 or 2编号相同且与WHERE two = 1 or 2编号相同的行,所以当它分组并回显它将回显标记为与颜色分组的数字。这是我的疑问:

    SELECT * FROM friends AS f5
INNER JOIN 
((SELECT one FROM friends WHERE two =  '1') AS f1,
(SELECT two FROM friends WHERE one =  '1') AS f2,
(SELECT one FROM friends WHERE two =  '2') AS m1, 
(SELECT two FROM friends WHERE one =  '2') AS m2)
ON (f1.one  = m1.one AND f2.two = m2.two ) 

但是当我在sql中查询此代码时,它显示了一个空结果。请帮忙吗?

0 个答案:

没有答案