Best Query

I have 2 tables
table 1
select * from table1 join table 2 on table1.1  = table2.1
but there are hundreds in table 2 and I only want to know if there is a match or not a match

so in table 1 I have 3 records- when I join to table2 I have hundreds

Kurt RossAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Sorry but I don not understand you are you asking.

If the columns in the join match between the tables then you will get all the rows.  That is the way joins work.

What I don't understand is what you mean by:   I only want to know if there is a match or not a match.

Can you provide some sample data and expected results?
Something like one of these?

select t1.*,  NVL( (select 'MATCH' from table2 t2 where and rownum = 1) , 'NO MATCH')
from table1 t1


select t1.*, nvl(t2.match,'NO MATCH')
 from table1 t1
left outer join  (select distinct id, 'MATCH' match from table2) t2
 on =
johnsoneSenior Oracle DBACommented:
For this, I always think of EXISTS, so I would do it this way:
SELECT t1.* 
FROM   table1 t1 
               FROM   table2 t2 
               WHERE = 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

EXISTS or IN or an INNER JOIN will only give you the implicit "match" criteria.  To get "no match" you need to include the rest of the rows
johnsoneSenior Oracle DBACommented:
I was making an assumption based on the original query that the join was what they were really only looking for matches.  You are correct that EXISTS wouldn't give the no match and the outer join would be the best way to go there.
Kurt RossAuthor Commented:
is there a way to add a third table matching the same criteria as the second to the first
so there would be 2 more columns from a third table saying null or showing the match>
slightwv (䄆 Netminder) Commented:
>>is there a way to add a third table


Personally I have no idea what you are looking for.  There also appears to be some confusion between the other Experts that posted.

Can you not post sample data and expected results?
johnsoneSenior Oracle DBACommented:
Agreed.  A third table should be able to be added, but I'm not entirely sure what you are looking for.  Sample data and results would be the easiest way to show what you are looking for as a final result.  Please be sure to include all 4 outcomes (assuming only 3 tables).
PortletPaulEE Topic AdvisorCommented:
An "exists" test seems to me to be the approach wanted to meet this:

"so in table 1 I have 3 records- when I join to table2 I have hundreds" [but I only want 3]

& I don't see anything specific in the question that leads to a need for a string "match" or "no match"

However the added requirement has morphed the question a bit it seems to me
"is there a way to add a third table matching the same criteria as the second to the first
so there would be 2 more columns from a third table saying null or showing the match"

If you want columns OF table3 in the result then join table3 into the query
If you merely wish to test for the existence of a match then you can use EXISTS
If you wish to suppress "unwanted repitition" in the results then perhaps you need to use a GROUP BY

There is a broad and generalized set of possible solutions because the question is vague. To get a more definitive answer please supply "sample data" and, from that data, the "expected result"
Kurt RossAuthor Commented:
Worked perfectly
what worked perfectly?

the accepted post doesn't offer an answer, only questions
Kurt RossAuthor Commented:
FROM   table1 t1
               FROM   table2 t2
               WHERE =
That answer, as acknowledged by the one who posted it does NOT give the requested results.
Kurt RossAuthor Commented:
it helped me figure out what I needed.
as I asked the question!
Kurt RossAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for KurtRoss's comment #a41382640

for the following reason:

the solution I have found
Odd someone else would tell me it isn't!
Kurt RossAuthor Commented:
it gives me the results I require!
Kurt RossAuthor Commented:
it was what I needed- so it was the solution I required
Please Close this ticket
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.