Question

Table tblusers:

+-------------+---------------+----------+
| id_users    | user          | password |
+-------------+---------------+----------+
| 1           | gurodrigues   | 1234     |
| 2           | lower52       | 123      |
| 3           | test55        | 1234     |
+-------------+---------------+----------+

Table 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

If I do this first SELECT it will return me a lot of duplicate rows, but I just need one time how can I do it?

And in another SELECT I have to get all users on tblexperiences WHERE has more than one row tblexperiences.id_users

Was it helpful?

Solution

SELECT tblusers.id, tblusers.user 
from tblusers
join tblexperiences ON tblexperiences.id = tblusers.id
group by tblusers.id, tblusers.user 

and for the second part of the question, add a

having count(tblexperiences.id) > 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top