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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:59:37+00:00 2026-06-02T04:59:37+00:00

I have found similar solutions online but none that I’ve been able to apply

  • 0

I have found similar solutions online but none that I’ve been able to apply to my specific problem.

I’m trying to “unique-ify” data from one table to another. In my original table, data looks like the following:

USERIDP1    USERIDP2     QUALIFIER     DATA
1           2            TRUE          AB
1           2                          CD
1           3                          EF
1           3                          GH

The user IDs are composed of two parts, USERIDP1 and USERIDP2 concatenated. I want to transfer all the rows that correspond to a user who has QUALIFIER=TRUE in ANY row they own, but ignore users who do not have a TRUE QUALIFIER in any of their rows.

To clarify, all of User 12’s rows would be transferred, but not User 13’s. The output would then look like:

USERIDP1    USERIDP2     QUALIFIER     DATA
1           2            TRUE          AB
1           2                          CD

So basically, I need to find rows with distinct user ID components (involving two unique fields) that also possess a row with QUALIFIER=TRUE and copy all and only all of those users’ rows.

  • 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-06-02T04:59:40+00:00Added an answer on June 2, 2026 at 4:59 am

    Although this nested query will be very slow for large tables, this could do it.

    SELECT DISTINCT X.USERIDP1, X.USERIDP2, X.QUALIFIER, X.DATA
    FROM YOUR_TABLE_NAME AS X
    WHERE EXISTS (SELECT 1 FROM YOUR_TABLE_NAME AS Y WHERE Y.USERIDP1 = X.USERIDP1
                  AND Y.USERIDP2 = X.USERIDP2 AND Y.QUALIFIER = TRUE)
    

    It could be written as an inner join with itself too:

    SELECT DISTINCT X.USERIDP1, X.USERIDP2, X.QUALIFIER, X.DATA
    FROM YOUR_TABLE_NAME AS X
    INNER JOIN YOUR_TABLE_NAME AS Y ON Y.USERIDP1 = X.USERIDP1
                                    AND Y.USERIDP2 = X.USERIDP2 AND Y.QUALIFIER = TRUE
    

    For a large table, create a new auxiliary table containing only USERIDP1 and USERIDP2 columns for rows that have QUALIFIER = TRUE and then join this table with your original table using inner join similar to the second option above. Remember to create appropriate indexes.

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

Sidebar

Related Questions

I have found similar problems on the web, but none of the posted solutions
I know a similar question has been asked but I have not found a
I know many people experience this problem, but the solutions I found online do
I've found a couple similar posts regarding this same problem, but none of the
I have tried to search for similar problems, but not found any good solutions.
I have found similar queries like mine in stackoverflow,but found no solutions . So
I have found some similar Que's on SO but had not find the solution.
I know that this is a repeated question. I have found very similar questions
I have found already some similar discussion on this, but would like to investigate
Morning, simple stupid question. I have found post with similar issues but after reading

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.