Solved

Oracle Query help: I want to be able to identify the values in TableA that are also located in TableB

Posted on 2011-02-28
3
386 Views
Last Modified: 2012-05-11
What query can I use for this? This is for an oracle database, and I'm using PL/SQL.
I want to be able to identify the values in TableA that are also located in TableB

TableA

FirstName            LastName
David            Smith
Mike            Smith
Arron            Smith


TableB

FirstName            LastName
Mark            Smith
Mike            Smith
Arron            Smith


So after I run my query, it will return...
Mike            Smith
Arron            Smith
0
Comment
Question by:silentthread2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 35002288
try this

SELECT A.FirstName, A.LastName
FROM tableA A
      INNER JOIN tableB B ON A.FirstName = B.FirstName AND A.LastName = B.LastName
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 35002370
If tableB can have duplicates, you can use

SELECT DISTINCT A.FirstName, A.LastName
FROM tableA A
INNER JOIN tableB B
  ON A.FirstName = B.FirstName AND A.LastName = B.LastName

or

SELECT A.FirstName, A.LastName
FROM tableA A
WHERE EXISTS (
  SELECT * FROM tableB B
  WHERE A.FirstName = B.FirstName AND A.LastName = B.LastName)
0
 
LVL 4

Expert Comment

by:pinkuray
ID: 35003847
You can go with the above as cyberkiwi said :

 
SELECT *
FROM TABLEA A
WHERE EXISTS
  (SELECT 1 FROM tableb WHERE FIRSTNAME =A.FIRSTNAME AND lastname =A.LASTNAME
  );
  
  
  
SELECT DISTINCT A.FirstName, A.LastName
FROM tableA A
INNER JOIN TABLEB B
  ON A.FirstName = B.FirstName AND A.LastName = B.LastName;
  
  
SELECT a.*
FROM TABLEA A ,
  TABLEB B
WHERE A.FIRSTNAME =B.FIRSTNAME
AND A.LASTNAME    =B.LASTNAME;

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to recover a database from a user managed backup

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question