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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:03:06+00:00 2026-05-31T12:03:06+00:00

I currently have the following query SELECT table1.col1, table2.col2 FROM table1 INNER JOIN table2

  • 0

I currently have the following query

SELECT table1.col1, table2.col2  
FROM   table1     
    INNER JOIN table2 ON table1.col1=table2.col6  
WHERE  col3 IN 
           (SELECT col1 
            FROM table3 
            WHERE col4 IN (
                   SELECT col4 
                   FROM table4 
                   WHERE col5 LIKE '%XYZ%'
               )       
            )  ORDER BY table1.col1 

The Result I get is as follows

COL1  |  COL2
Bob      LA
BOB      NY
Charlie  SF
Donald   Phoenix
Edward   Chicago
Edward   DC
Florence Miami
George   Sunnyvale
Helen    Orlando
Helen    Houston

If you observe the results, the following entries are duplicated on Col1 (Bob, Edward, Helen). The following are only single records(Charlie, Donald, Florence, George).

What I want are 2 different queries where one query should return only the single records and another query should return only the duplicates. “I need BOTH Col1 and Col2 returned from both the queries”. I have tried to modify, but either it gives an error or it does not result in any reults .

Desired result

Query1 result (Only single records)

COL1  |  COL2
Charlie  SF
Donald   Phoenix
Florence Miami
George   Sunnyvale

Query2 result (Only duplicate records returned)

COL1  |  COL2
Bob      LA
BOB      NY
Edward   Chicago
Edward   DC
Helen    Orlando
Helen    Houston
  • 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-31T12:03:07+00:00Added an answer on May 31, 2026 at 12:03 pm

    And if it isn’t Oracle, get familiar with the GROUP BY xxx HAVING yyy = z construct.

    Simply adding it to your query won’t work because you want to select also a column you are not grouping by, but here is one simple way of eating your cake and having it:

    SELECT table1.col1, table2.col2  
    FROM   table1     
    INNER JOIN table2 ON table1.col1=table2.col6  
    WHERE  col3 IN 
           (SELECT col1 
            FROM table3 
            WHERE col4 IN (
                   SELECT col4 
                   FROM table4 
                   WHERE col5 LIKE '%XYZ%'
               )       
            )
    AND col1 IN (
        SELECT table1.col1
        FROM   table1     
            INNER JOIN table2 ON table1.col1=table2.col6  
        WHERE  col3 IN 
           (SELECT col1 
            FROM table3 
            WHERE col4 IN (
                   SELECT col4 
                   FROM table4 
                   WHERE col5 LIKE '%XYZ%'
               )       
            )
        GROUP BY table1.col1
        HAVING COUNT(table1.col1) > 1
    )
    ORDER BY table1.col1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I have a select query that currently produces the following results: Description Code Price
Dear all, I have a select query that currently produces the following results: DoctorName
currently I have the following code: String select = qry.substring(select .length(),qry2.indexOf( from )); String[]
I have the following code: Query query = this.getSession().createSqlQuery(select * from db@server:table where 1=1);
I currently have the following js code function clearMulti(option) { var i; var select
I have the following query, SELECT `candidates`.`candidate_id`, `candidates`.`first_name`, `candidates`.`surname`, `candidates`.`DOB`, `candidates`.`gender`, `candidates`.`talent`, `candidates`.`location`, `candidates`.`availability`,
Given the following table in SQL Server 2005: ID Col1 Col2 Col3 -- ----
I have the following problem. I am currently trying to return information from a
I'm using a SQL query that is similar to the following form: SELECT col1,

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.