473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Query to Find Unmatched Data

hiii...

I have user data in a two column table..

table A
id___name
01___jason
02___robert
03___cecil
04___linda
05___dave

table B
id___employ
02___manager
03___teller
04___teller

i want to compare it.
i want to choose the one in the rows that does not exist in table B..

for example : 01__manager from table B

thx
Jul 2 '11 #1
2 6211
Rabbit
12,516 Expert Mod 8TB
Please don't double post your questions.

Three things.
1) To find records that exist in a table x that don't exist in another table y, you can outer join the tables and filter for the nulls in the joined field(s) in y.

2) In your example, there is no record of 01_Manager and there is no way of knowing that 01 is a manager because no such information exists. All that can be said is that record 01 does not exist in table B. What position they hold is irrelevant.

3) There is no need to separate out these columns into different fields unless one person can hold multiple positions.
Jul 2 '11 #2
nbiswas
149 100+
Hi,
As Rabbit has rightly pointed out, your question is a little unclear. However, I am assuming the below tables

TableA
Expand|Select|Wrap|Line Numbers
  1. ID    Name
  2. 1    Jason
  3. 2    Robert
  4. 3    Cecil
  5. 4    Linda
  6. 5    Dave
And

TableB

Expand|Select|Wrap|Line Numbers
  1. ID    Name
  2. 1    Manager
  3. 2    Teller
  4. 3    Teller
  5. 4    Linda
  6. 5    Dave
The below ddls will help to create the test environment

Expand|Select|Wrap|Line Numbers
  1. Declare @tableA table(ID int Identity,Name varchar(20))
  2. Insert into @tableA 
  3. Select 'Jason' union all Select 'Robert' Union all select 'Cecil' Union all select 'Linda'
  4. Union all select 'Dave'
  5. Select * from @tableA 
  6.  
  7. Declare @tableB table(ID int Identity,Name varchar(20))
  8. Insert into @tableB 
  9. Select 'Manager' union all Select 'Teller' Union all select 'Teller' Union all select 'Linda'
  10. Union all select 'Dave'
  11. Select * from @tableB
Objective

We are interested to find out those employees that are not in table A. So the desired output in this case will be

Expand|Select|Wrap|Line Numbers
  1. ID    Name
  2. 1    Manager
  3. 2    Teller
  4. 3    Teller
Query 1: Using Except

Expand|Select|Wrap|Line Numbers
  1. Select * from @tableB except(Select * from @tableA )
Query 2: Using Not In
Expand|Select|Wrap|Line Numbers
  1. Select B.ID,B.Name 
  2. From @tableB B
  3. Where B.Name Not In(Select Name from @tableA)
Query 3: Using Left Join And filter condition for Nulls

Expand|Select|Wrap|Line Numbers
  1. Select B.ID,B.Name 
  2. From @tableB B Left Join @tableA A
  3. On A.Name = B.Name
  4. Where A.Name Is Null
Query 4: Using Not Exists

Expand|Select|Wrap|Line Numbers
  1. select B.ID,B.Name 
  2. from @tableB B 
  3. where not exists ( Select Name from @tableA A where A.Name = B.Name)
Hope this helps.

Kindly let me know in case of any concern
Jul 4 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot find a software.design group. I would like to...
26
by: rkleiner | last post by:
Is there a regular expression to find the first unmatched right bracket in a string, if there is one? For example, "(1*(2+3))))".search(/regexp/) == 9 Thanks in advance.
0
by: duraisridhar | last post by:
hi all., How can I find the Data Base which can't backed up for reasons like Data Base is in the middle of the Restore before i start Backup Process . Regards., Sri
5
by: chellappa | last post by:
Hi All, How to find the data type of the variable ? is there any libaray function avaiable? Because i want create generic data type of some operation . Thanks All By Chellappa
5
by: CindySue | last post by:
I have a table called LP that has name, address, phone and some other types of information. Periodically I receive a delimited text file that has all current information. I don't want to replace the...
1
by: Luqman | last post by:
I have created a Insert Query in Sql Data Source using Oracle Database, with the parameters, and its connected with DetailView Control. When I try to Insert through DetailView Control, Illegal...
2
by: flipperqm | last post by:
I have 2 queries with alot of data but when i run the find unmatched query wizard, i tell it which 2 queries but when it asked me to tell it which 2 fields to match, it doesn't show any fields . They...
2
by: ilikebirds | last post by:
In 1 Database(ttt) I currently have a Union Query that collects data from 4 databases (a,b,c,d) and then a MakeTable query that combines all of those into a table. ( Union A,B,C,D to make table in...
1
by: AccessHunter | last post by:
Please Help.... I have a query with 2 tables, LegalFile and Cases. LegalFile has the field CaseID(Number Field) and Cases has CaseNbr(Text Field). I am trying to find entries that are in...
0
by: Alexandre Brisebois | last post by:
I have been trying to use Linq o SQL to query an XML data column I currently have in my DB, but it seems that Linq to SQL sees a typed xml column as an XElement, I don't want to get the full...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.