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 3788006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:55:50+00:00 2026-05-19T11:55:50+00:00

I have what seems to be a simple problem, but can not figure out

  • 0

I have what seems to be a simple problem, but can not figure out the proper solution via SQL. I’m using postgresql specifically.

Take the following:

SELECT *
FROM users INNER JOIN tags
  ON (tags.user_id = users.id)
WHERE tags.name IN ('word1', 'word2')

This does not do what I need. I want to find users whose tags are ONLY included in the list. If the user has a tag that is not in the list, the user should not be included.

‘user1’ tags: word1, word2, word3
‘user2’ tags: word1
‘user3’ tags: word1, word2

Given: word1 and word2. I want to prepare a query that returns ‘user2’ and ‘user3’. ‘user1’ is excluded because it has a tag that is not in the list.

Hopefully I made this clear. Thanks for your help!

  • 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-19T11:55:50+00:00Added an answer on May 19, 2026 at 11:55 am

    Relying on COUNT(*) = 2 will require that there can be no duplicates of user_id and name in the tags table. If that’s the case, I’d go that route. Otherwise, this should work:

    SELECT u.* 
    FROM users AS u
    WHERE u.id NOT IN (
        SELECT DISTINCT user_id FROM tags WHERE name NOT IN ('word1', 'word2')
    ) AND EXISTS (SELECT user_id FROM tags WHERE user_id = u.id) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a really, really simple problem, but I can't figure it out.
I have what seems to be a simple problem but I can't figure it
I have a very simple problem, but I can't seem to solve it. I
I have a simple Poco-Model using abstract classes, and it seems not to work
I'm having a slight problem that I can't figure out, but should be really
this seems simple but I cannot figure out how to do it or the
I have what seems like a simple problem. I have a Spring web app,
This seems like a simple problem: I have a WF4 activity that guides the
I have this simple example I can't seems to get working : MERGE INTO
It seems I can't easily have an XSD declaration for this simple XML <root>

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.