473,809 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

merging three tables with into another with sql

42 New Member
I have already achieved this in access and was trying with straight SQL earlier I would just like to know what I'm doing wrong in sql or what syntax I'm missing. I have three tables with identical data that was created from .txt delimited files I have received. I tried the following code.

Expand|Select|Wrap|Line Numbers
  1. SELECT VIN, OtherID, Rego, DriverName, OwnerName, VehicleDescription, ExpiryDate, Address, City, Postcode, State INTO Iload
  2. FROM STDhy60, STDhy59, STDhy55
  3. WHERE VehicleDescription like '*iLOAD*';
So basically I am trying to get the records from three tables that contain iload as a value into a new table. In the end I just imported the information into a table called STD then imported the other two .txt files into that table using access. Then wrote an sql statement to get the information I needed out of one table which works.

Expand|Select|Wrap|Line Numbers
  1. SELECT VIN, OtherID, Rego, DriverName, OwnerName, VehicleDescription, ExpiryDate, Address, City, Postcode, State INTO Iload
  2. FROM STD
  3. WHERE VehicleDescription like '*iLOAD*';
The first code basically causes an error, this field may exist in more than one table. I not comparing values though I just want all the records which are unique into another table using SQL statement similiar to the first bit of code.
Apr 28 '08 #1
1 1752
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. There are two problems with the first SQL statement you list. The first is the use of non-unique field names, and the second is that there are no joins between the tables.

When the same field name is present in more than one of the tables selected you need to qualify the field name with the name of the table you are selecting it from, throughout the SQL:

tablename.field name

or where there are spaces in the names

[name of table].[name of field]

If you look at the SQL that Access creates (View, SQL View) from the graphical query editor you will see that Access itself always creates fully qualified field references throughout, and you may well have to do the same throughout yours.

There were no INNER JOINs in your first SQL statement, and this will mean that you end up multiplying all rows of the first table by the rows of the second and third tables. This gives what is known as the Cartesian Product of the tables. If there were 100 rows in the first, 200 in the second and 300 in the third you will end up with 100x200x300 rows, 6,000,000 rows in the product table. Cartesian products grow very rapidly. You would need to define the common field or fields joining the tables to avoid this happening, using an appropriate INNER JOIN statement.

Given that you have three separate tables the JOIN approach is fundamentally wrong, as the tables do not contain rows in common (as far as I can tell from what you have told us).

It would be better in my opinion to have three separate append queries, one for each table, then create a macro to run all three one after the other as one operation.

-Stewart
Apr 28 '08 #2

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

Similar topics

15
2938
by: Ike | last post by:
Suppose I have a relational database, called "BranchA." I have a second relational database, of identical structure to BranchA, but with different data, and this one is called BranchB. Can I merge the two, into, say, a BranchC somehow on occassion? Thanks, Ike
5
4046
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I think - it might have been XP) to 2003. The database is impressive, both in what it does and the obtuse and inconsistent ways it works. There are several hundred queries, for example, with no indication of where they are used or if they are in fact...
1
4966
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word 1. Query..I want to keep the fields seperatred. I do not want to sent on field with all accumulated languages from one person to Word. Each language should appear in the document in a separate cell Cross tables are not delivering the result I...
2
1820
by: Bubb | last post by:
I have an Access database with one table that I use for stuff I sell online. Each record has the following fields: Unique Id, Cost, and Item Description. I just obtained some more stuff with its own database, some of the items I already have in my database. The new table has the same three fields. What I need to do is merge the two database tables together so I have one table. I need to make the new merged table have 7 fields: ...
1
1539
by: mrclash | last post by:
Hello, I have a Database in a SQL Server 2000 where I have different users tables with equal fields like this: id (int) email (varchar) name (varchar) address (varchar) joinedon (datetime)
1
3406
by: actimel01 | last post by:
I know this question has been asked many times before but I can't find an answer that fits my data! I have two Access databases. The tables in each have the exactly the same fields except for one (which was added into the tables in the second database). Thye do have different records. I want to merge the records from the tables from in the first database into the tables in the second. Other answers have suggested merging the tables in a...
1
1672
by: John | last post by:
Hi I have two tables with two columns each. Each table has an id column and a value column. I would like the two tables to be merged so there are three columns id, valuefromtable1 and valuefromtable2 and in such as way that all records from both tables are included but where they don't match the corresponding valuefromtable1 or valuefromtable2 is empty. How can I go about doing this? Thanks
6
1972
by: John | last post by:
Hi I have three tables with a common id with which they can be linked. I need to merge them in a way that the resultant table has all records from three tables. Below is what sort of result I am expecting; Table 1 ID Value1 1 A1
1
1195
by: rossan | last post by:
Hi! I have a small database specifically for Project Registration with one of the tables called regContractors. The fields for this table are from three different tables of the main Contractors database. Which should be an easy way to update such a table from those 3 different tables Rgds Ross
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.