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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:47:10+00:00 2026-05-19T14:47:10+00:00

I have a problem with an inherited database for which the person who originally

  • 0

I have a problem with an inherited database for which the person who originally set it up left little documentation.

I have a set of users, each with three potential occupations. When queried, it returns values like these:

USER_ID CAREER_ID   TITLE
1       44           Agricultural Engineer
1       136          Educational Psychologist
1       132          Clinical Psychologist
18      245          3D Designer
18      2            Accountant - Private Practice
18      1            Accountant - Industry and Commerce
19      245          3D Designer
19      2            Accountant - Private Practice
19      1            Accountant - Industry and Commerce
20      128          Advice Centre Worker
20      130          Careers Adviser
20      129          Care Assistant
21      1            Accountant - Industry and Commerce
21      245          3D Designer
21      2            Accountant - Private Practice
23      245          3D Designer
23      2            Accountant - Private Practice
23      1            Accountant - Industry and Commerce
29      245          3D Designer
29      2            Accountant - Private Practice
29      1            Accountant - Industry and Commerce
30      219          PC Games Tester
30      173          Bouncer
30      103          Stunt Person
32      245          3D Designer
27      2            Accountant - Private Practice
27      1            Accountant - Industry and Commerce
27      245          3D Designer
30      219          PC Games Tester
30      173          Bouncer
30      103          Stunt Person

As you can see, for some reason, careers 1, 2, and 245 are set as defaults. Now, I want to filter out the users that have that specific set of careers, but not all instances of them, as any user could have legitimately chosen one or two of the set.

I can live with filtering out the odd character who just might have actually chosen that particular set on purpose.

Hope someone can help. I’m sure the solution is rather simple, but I can’t come up with it.

  • 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-19T14:47:11+00:00Added an answer on May 19, 2026 at 2:47 pm
    Select ...
    From Occupations O
    Where Not Exists    (
                        Select 1
                        From Occupations O1
                        Where O1.Career_Id In(1,2,245)
                            And O1.User_Id = O.User_Id
                        Group By O1.User_Id
                        Having Count(*) = 3
                        )
    

    Another solution:

    Select ...
    From Occupations O
    Where Exists    (
                    Select 1
                    From Occupations O1
                    Where O1.Career_Id Not In(1,2,245)
                        And O1.User_Id = O.User_Id
                    )
    

    The catch with the above solution is that it will exclude those that only have fewer than all three default careers. I.e., it will exclude users that only have (1,2), (1,245), (2,245), (1), (2), (245). If they must have all three and only those three, then you need to modify this solution like so:

    Select ...
    From Occupations O
    Where Exists    (
                    Select 1
                    From Occupations O1
                    Where O1.Career_Id Not In(1,2,245)
                        And O1.User_Id = O.User_Id
                    )
    Or Exists   (
                Select 1
                From Occupations O2
                Where O2.User_Id = O.User_Id
                Having Count(*) < 3
                )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited a (rather large) database, which at the moment is only ever
i have problem with autorotate on iphone i set up in all classes -
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a database of events which gets updated every night. A single event
Imagine the following problem: You have a database containing about 20,000 texts in a
i have a problem which is i believe basic for most of the RoR
I have inherited a Access database that has a query that SELECTs over 50
Suppose you have inherited a massive spreadsheet which contains lots and lots of data.
A have a problem with PHP application, that I'm working on. Main page which
I have a mysql database which as one of the fields contains a html

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.