例如,我有两个表:
ID | Name
------------
1 | test 1
2 | test 2
ID2| ID | Age
--------------
1 | 1 | 18
2 | 1 | 18
3 | 1 | 19
4 | 2 | 18
5 | 2 | 19
我想要所有具有名称和年龄多个列的记录,但我不知道该怎么做。
我想要这样的输出:
Name | Age
--------------------
test 1 | 18
test 1 | 18
有人可以帮助我吗?
最佳答案
尝试以下查询:
Select t1.*, t2.*
from table1 t1
join table2 t2
on t1.id = t2.id
join (select id, age
from table2
group by id, age
having count(*) > 1
) t3
on t1.id = t2.id and t2.id = t3.id and t2.age = t3.age
关于mysql - 如何在 SQL 中获取具有两个对应列的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54618589/