E
E
Egor Mikheev2017-08-22 09:31:24
MySQL
Egor Mikheev, 2017-08-22 09:31:24

How to get a column entry that matches each of the specified entries in another column?

I have a table that contains many-to-many relationships.
UserID Roomid Dateadd ID
2E8BA91E-C091-437A-8823-43C403D52D87 2066 08/21/2017 20: 11: 15.257 5
2E8BA91E-C091-437A-8823-43C403D52D87 2067 08/21/2017 20: 11: 40.477 7
5C8DE7B8-ABB0-417C-971E- b2217d6a3652 2066 08/21/2017 20:11:23.197 6
cacb2d37-0d73-4848-8758-b5af8841b13d 2067 08/21/2017 20:11:
43.260
I have a solution, but it seems to me that it is not optimal.

SELECT
  c.RoomId
FROM (SELECT
    UserRooms.RoomId
   ,COUNT(*) AS RoomCount
  FROM dbo.UserRooms
  WHERE UserRooms.UserId IN ('2e8ba91e-c091-437a-8823-43c403d52d87', '5c8de7b8-abb0-417c-971e-b2217d6a3652')
  GROUP BY UserRooms.RoomId) c
WHERE c.RoomCount = 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Mikheev, 2017-08-22
@ogregor

https://ru.stackoverflow.com/questions/708895/%D0%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question