I have question about the sql query.
I am trying to make the query that user who has all gun type times. For example.
I have table
ITEM.
|itemid |item_name|
| 1 | GunBow |
| 2 | GunLong |
| 3 | GunShot |
|4 | SwordSm |
|5 | SwordLg |
|6 | Cannon |
and I have table
userinventory
|used_id | name_item |
|1 | GunBow |
|1 | GunLong |
|1 | GunShot |
| 2 | GunBow |
|2 | SwardLg |
| 2 | Cannon |
| 3 | GunBow |
| 3 | GunShot |
Since user “1” has all of guns, I would like make query that returning the user 1.
What I did was…
Create Table #tmp(
Classname [varchar](50) NOT NULL
)
INSERT INTO #tmp SELECT DISTINCT iteam_name
FROM ITEM WHERE item_name like 'Gun%'
then…. I would like to compare to find user who has all of item..
However, I am not really sure how to do it.. because I can not use count or any aggression
Does anyway know they way to find user id who has all of Gun?
Check the solution here on SQL Fiddle – http://sqlfiddle.com/#!3/d10b2/1