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
And if it isn’t Oracle, get familiar with the
GROUP BY xxx HAVING yyy = zconstruct.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: