表tblusers
:
+-------------+---------------+----------+
| id_users | user | password |
+-------------+---------------+----------+
| 1 | gurodrigues | 1234 |
| 2 | lower52 | 123 |
| 3 | test55 | 1234 |
+-------------+---------------+----------+
表tblexperiences
:
+----------------+-----------+-------------------+
| id_experience | id_users | detail |
+----------------+-----------+-------------------+
| 1 | 1 | 'Cool, fantastic' |
| 2 | 1 | 'Nice!!' |
| 3 | 2 | 'Boring' |
+----------------+-----------+-------------------+
SELECT tblusers.id, tblusers.user from tblusers, tblexperiences WHERE tblexperiences.id = tblusers.id
如果我先执行此操作SELECT
,它会返回很多重复的行,但我只需要一次,我该怎么办呢?
在另一个SELECT
中我必须让tblexperiences
上的所有用户WHERE有多行tblexperiences.id_users
答案 0 :(得分:1)
SELECT tblusers.id, tblusers.user
from tblusers
join tblexperiences ON tblexperiences.id = tblusers.id
group by tblusers.id, tblusers.user
并且对于问题的第二部分,添加
having count(tblexperiences.id) > 1