Reputation: 11
I have table in which I inserted all the liked places records. Like: I have table PlaceLikes;
Id placeId likedByUserID
1 ABC 1
2 DEF 1
3 ABC 2
4 FFF 2
Result: User 1 want to get all placeID that matches with itself.
Id placeId likedByUserID
3 ABC 2
Here User 2 with ABC placeId is similar with Requestor User ID 1. So, How I can filter the data like this
Upvotes: 0
Views: 49
Reputation: 28
I think this piece of query will be able to solve your problem statement as understood by me.
DECLARE @sample_name VARCHAR (10);
SET @sample_name = 'placeId to be searched'
SELECT Id, placeId, likedByUserID FROM demo_table dt
WHERE dt.placeId = @sample_name
Do let me know if this was helpful.
Upvotes: 0
Reputation: 222582
You can use exists
:
select t.*
from mytable t
where
t.likedByUserID <> 1
and exists (
select 1 from mytable t1 where t1.place_id = t.place_id and t1.likedByUserID = 1
)
Upvotes: 1