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

Combining multiple Access tables using C#

Hello everyone,

I'm having a bit of trouble with something. What I'm trying to do is create a new Access table by combining other already existing Tables.
For instance, let's consider Table1 (with columns A, B and C), Table2 (with columns A, D and E) and Table3 (with columns A, F and G), where Table1.A = Table2.A = Table3.A. From these, I want to create a new table TableResult, with columns A, B, C, D, E, F and G, with all the data contained in them. There's one catch: I want the code to get the names of the other columns, apart from column A.
I've thought about using Union, but I need to actually create a new table by combining the previous tables.

Any ideas?

Thanks in advance!
Aug 14 '12 #1

✓ answered by Yaridovich

That didn't work, but it helped me find the correct syntax - I just need to add parenthesis to the first join. Like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. INTO TableResult
  3. FROM (Table1
  4. INNER JOIN Table2
  5. ON Table1.A = Table2.A)
  6. INNER JOIN Table3
  7. ON Table1.A = Table3.A
Thanks for the help!

11 4633
Rabbit
12,516 Expert Mod 8TB
Use a join. But you should only do this if the tables are related 1 to 1. Otherwise you're going to end up duplicating information and end up with denormalized data.
Aug 14 '12 #2
@Rabbit - Can you give me an example as how to do it using Join? Also, I forgot to add something to the original post. I just edited it and added this: "There's one catch: I want the code to get the names of the other columns, apart from column A."
Aug 14 '12 #3
Rabbit
12,516 Expert Mod 8TB
The SQL code to join a table is
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM tableA
  3. INNER JOIN tableB
  4. ON tableA.IDField = tableB.IDField
Aug 14 '12 #4
@Rabbit - But how can I save the resulting table into a new table? Is there any way of combining "Create Table" and "Join"?
Aug 14 '12 #5
Rabbit
12,516 Expert Mod 8TB
You can use a select into to create a table from a query.

If you're strugling with basic SQL, you should read a tutorial before taking on a project.
Aug 14 '12 #6
It's just that, in the work I do, I don't use SQL queries much, it's basically just simple stuff. Now I'm needing to do some more complex stuff. And it seems that creating a table from an inner join isn't that simple.

I'm trying to do this, but it's not working. I've tried moving the closing parenthesis to the end, but it doesn't work either.

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. INTO TableResult
  3. FROM
  4. (
  5.    SELECT *
  6.    FROM Table1
  7.    INNER JOIN Table2
  8.    ON Table1.A = Table2.A
  9. )
  10. INNER JOIN Table3
  11. ON Table1.A = Table3.A
Aug 14 '12 #7
Rabbit
12,516 Expert Mod 8TB
There's no need to subquery the first join.

But the reason it's not working is because you didn't alias the subquery. Outside of a subquery, you don't have access to the table names used inside the subquery.
Aug 15 '12 #8
Could you help me write the correct query? I've tried multiple things, but none are working, there's always some syntax error.

I've tried these:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. INTO TableResult
  3. FROM
  4. (
  5. SELECT *
  6. FROM Table1 AS T1
  7. INNER JOIN Table2 AS T2
  8. ON T1.A = T2.A
  9. INNER JOIN Table3 AS T3
  10. ON T1.A = T3.A
  11. )
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. INTO TableResult
  3. FROM
  4. (
  5. SELECT *
  6. FROM
  7. (
  8. SELECT *
  9. FROM Table1 AS T1
  10. INNER JOIN Table2 AS T2
  11. ON T1.A = T2.A
  12. )
  13. INNER JOIN Table3 AS T3
  14. ON T1.A = T3.A
  15. )
Aug 15 '12 #9
Rabbit
12,516 Expert Mod 8TB
Like I said, a subquery isn't necessary.
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2. INTO ...
  3. FROM tableA
  4. INNER JOIN tableB
  5. ON tableA.ID = tableB.ID
  6. INNER JOIN tableC
  7. ON tableA.ID = tableC.ID
Aug 16 '12 #10
I tried that, but I just remembered I tried that while using alias. I'm gonna try it again, this time I'll do it like that. I'll then get back here to tell you if it worked. Thanks!
Aug 16 '12 #11
That didn't work, but it helped me find the correct syntax - I just need to add parenthesis to the first join. Like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. INTO TableResult
  3. FROM (Table1
  4. INNER JOIN Table2
  5. ON Table1.A = Table2.A)
  6. INNER JOIN Table3
  7. ON Table1.A = Table3.A
Thanks for the help!
Aug 16 '12 #12

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

Similar topics

0
by: Bob C. | last post by:
I am considering combining one large Access db and several small Access db's into a single SQL Server 2000 db. The small db's serve separate but related functions in our operation, and they all...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
6
by: Stuart Clark | last post by:
Hiya I'm learning ASP using Access and Dreamweaver. I've just started simple and I've tried to make the db show the results of just two tables without doing anything clever! I have the following...
1
by: Ken | last post by:
Help! I have a MS Access database made up of a single table. The data updates for this database comes in the form of a single Excel spreadsheet, which is imported into the database table. I...
4
by: Oceania | last post by:
Hi All, I did try using the sample code from the ADO.net forum to link one table, it is working fine. But, I got a problem when I tried to link all tables (20 tables)... Please help, thank...
2
by: dollyvishal | last post by:
How to get constraint information for MS Access tables using Query?
23
nehashri
by: nehashri | last post by:
hi i am designing a database using Ms Access and ASP. i have 3 tables in access namely 'PERSONAL', other as 'POLICY' and 3rd one is named as 'STAFF'. in the contact table i have ID, Name, Children...
5
by: rewalk | last post by:
Hello all, I've set up protected Excel sheets that users can paste data into. I then need to be able to pull the data they paste into multiple access tables and then reset the Excel spreadsheet...
3
by: simple simon | last post by:
How would I insert into multiple related tables using a table valued parameter? Is there any way to do this without using a WHILE loop? I know how to insert from a table valued parameter into one...
3
by: Teresa Barnacle | last post by:
Hi Need a little help or advice. I have a DBase with 2 tables a. Candidate Personal Details b. Candidate Registration Detail (reg for a qualification) A customer fills out a excel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.