Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:15:38+00:00 2026-05-31T13:15:38+00:00

I have question about the sql query. I am trying to make the query

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:15:39+00:00Added an answer on May 31, 2026 at 1:15 pm
    SELECT Q.user_id
    FROM
    (
      SELECT DISTINCT item_name FROM item WHERE item_name LIKE 'Gun%'
    ) P,
    
    (
     SELECT DISTINCT X.name_item,Y.user_id
     FROM userinventory X, 
      (SELECT user_id,COUNT(DISTINCT name_item) as count_guns_userid
      FROM userinventory
      WHERE name_item LIKE 'Gun%'
      GROUP BY user_id
     )Y
    WHERE X.user_id=Y.user_id  
    ) Q
    WHERE P.item_name=Q.name_item
    GROUP BY Q.user_id
    HAVING COUNT(Q.name_item)=3;
    

    Check the solution here on SQL Fiddle – http://sqlfiddle.com/#!3/d10b2/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a question about SUM in sql, I have a query that
I want to make one question about oracle/sql query. I have some data like
i have a general question about how sql server evaluates the joins.The query is
I have a table in SQL Server 2000 that I am trying to query
I have a question about the fastest way to perform a SQL Server query
I have a question about SQL Server indexes. I'm not a DBA and assume
I am new to php and sql, and i have one tiny question about
I have a SQL query that contains a derieved table. The derived query looks
I have a sql server 2005 table called ZipCode, which has all the US
I have a question about the SQL standard which I'm hoping a SQL language

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.