473,425 Members | 1,872 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,425 software developers and data experts.

Combine Two Tables

8
Hi,

I'm trying to select distinct records from TableA and TableB below, but I'm getting multiple records. For example ClientID 102 returns 24 record using the query below. What is the best way to avoid duplicated records.


Expand|Select|Wrap|Line Numbers
  1. select *
  2. from TableA a inner join TableB on (a.clientid = b.clientid)
  3. order by a.ClientID
  4.  
Expand|Select|Wrap|Line Numbers
  1. TableA
  2. TAiD ClientID    LicenseID   InUse   ProductVersion
  3. 533    102    1        8500    4.5.2
  4. 534    102    2         600    4.5.8
  5. 535    102    3         461    4.5.2
  6. 536    102    4          450    4.5.6
  7. 527    103    1         4649    5.2.2    
  8. 528    103    2          1        5.2.2    
  9. 529    103    3         132    5.2.2    
  10. 530    103    6          0        5.2.10    
  11. 531    103    4          6        5.2.2    
  12. 532    103    8        4486    5.2.10    
  13.  
  14. TableB
  15. TBiD    ClientID  ProductNM    ProdDesc    ProdID       ProdType
  16. 12    102    ABC-DC1        ABC DC       192-162    DC
  17. 13    102    ABC-DC2        ABC DB2       192-163    DC
  18. 14    102    ABC-TT         ABC Tele   192-166    TT
  19. 15    102    ABC-WE1        ABC We1       192-164    WE
  20. 16    102    ABC-WE2        ABC We2       192-165    WE
  21. 17    102    ABC-Test    ABC Test   192-167    TEST
  22. 18    103    AVA-NOS        Ava NOS       192-513    NOS
  23. 19    103    AVA-TEST    Ava Test   192-561    TEST
  24. 20    103    AVA-WEB        Ava Web       192-560    WEB
  25.  

Thanks,
Jul 8 '10 #1
4 1867
ck9663
2,878 Expert 2GB
Because you use "*".

If you want to return all distinct ClientId you're going to have to return just the ClientId. If you include any other column, the distinct combination of the columns on your SELECT clause will be returned.

Expand|Select|Wrap|Line Numbers
  1.  
  2. select distinct a.clientid
  3. from TableA a 
  4. inner join TableB on (a.clientid = b.clientid)
  5. order by a.ClientID
  6.  
  7.  
That will only return all ClientId that exists on both table.

Happy Coding!!!

~~ CK
Jul 8 '10 #2
ejbatu
8
Thank you, but I don't think it will ever work the way I expected it to work.
Jul 9 '10 #3
You have 24 records for client with id = 102 because you have 24 different products for this client. If you want only one record you have to define what product you want to see
Jul 10 '10 #4
Delerna
1,134 Expert 1GB
you have 4 records in table a for clientID=102

you have 6 records in table b for clientID=102

if you join table a to table b using clientID as the only join parameter, then each of the 4 records in table a will join to each of the 6 records in table b
in other words you will have 6 lots of each of the 4 records in table a because each one joins to each of the 6 records in table b


4 * 6 = 24 records.



From your confusion I surmise that the relationship must be more than simply the ClientId and yet I see no other fields in the 2 tables that indicate a relationship between them.

If my surmation is correct then
What is the other relationship between the 2 tables besides ClientID
You need to identify it and include it as a join condition in addition to ClientID
Jul 13 '10 #5

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

Similar topics

1
by: snOOp | last post by:
I am trying to combine the data from two similar tables into one query, but I need for all of the records from both tables to show up and I want the ones that have matching 'emplid' to be combined...
1
by: Eli Sidwell | last post by:
I have an Access DB that contains 5 tables for the last 5 years. All 5 tables have the same structure. I wanted to keep each year separate for organizational purposes. But, I want to query all 5...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
2
by: Sal | last post by:
Sorry for the vague subject, not sure how to properly sum up what I need to do. I have 2 tables Tbl1 is single field: CODE 2115-GOR
1
by: Sergio | last post by:
Hello everybody. Somebody has given me nine files with some data for the years 1997, 1998, ... , 2005. They are 9 different mdb files. Each one has many tables, forms, and other things. But all...
1
by: Alex Chun | last post by:
How can I make a Query that combines tables, so that if table1 has records "apples", "pears" and table2 has records "apples", "cherries", the query result will be "apples", "pears", "cherries"? ...
2
by: nugz | last post by:
I want to combine 3 tables with like data then append it with a filter. Tables: NewStarts, Complaints, Memos Combine: Date, Address, Route, Pub, etc.... Then sort: previous 8 days, pub/freq...
1
by: Bombus | last post by:
Hello. I have MS Access 2003 and Visual Basic 6.0. In the Access database and two tables tblA and tblB that have a common field fldPN (Personal Number). I use ADO connection. From tblA I...
1
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script...
3
by: stateemk | last post by:
Hi, I'm probably making this much harder than it needs to be, but I just can't think of how to do this. Each year, a database is created with all employees on it. I need to pull all the employees...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.