0

I don't know if the question title is so clear, but here is my question:

I had table UsersMovements which contains Users along with their movements

UsersMovements:

ID
UserID
MovementID
Comments

I need help looking for a query which would give me if users 1, 2 & 3 had been in a common MovementID, knowing that I had know what is the MovementID

The real case is that I want to see if those X users which I would select been in an area (in a limited interval, assuming I had date/Time in the table)

Thank you

  • 2
    Make it easy to assist you, show us some sample table data and the expected result - all as formatted text (no images.) [mcve] – jarlh Feb 23 '21 at 21:05
  • You'll probably end up using GROUP BY and HAVING. – jarlh Feb 23 '21 at 21:06

1 Answers1

0

The following returns all movement ids that have all three users:

select movementid
from usermovements
where userid in (1, 2, 3)
group by movementid
having count(distinct userid) = 3
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786