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

Need to combine 2 tables into 1 uniquely-rowed table - help

Is this how it's done?

INSERT INTO student (
(SELECT DISTINCT a.*
FROM student_spring a, student_summer b
WHERE a.unique_key != b.unique_key)\
UNION
(SELECT DISTINCT b.*
FROM student_summer b, student_spring a
WHERE b.unique_key != a.unique_key)
)

I'm trying this but I keep losing data whenever I run this!

Also, how do I populate a database table from an XML file?

Thanx
Phil

Feb 28 '06 #1
3 2420
ph**************@gmail.com wrote:
Is this how it's done?

INSERT INTO student (
(SELECT DISTINCT a.*
FROM student_spring a, student_summer b
WHERE a.unique_key != b.unique_key)\
UNION
(SELECT DISTINCT b.*
FROM student_summer b, student_spring a
WHERE b.unique_key != a.unique_key)
)

I'm trying this but I keep losing data whenever I run this!

Also, how do I populate a database table from an XML file?

Thanx
Phil

I am guessing that student_summer and student_spring tables are
identical and you want to get a distinct list of students from both
summer and spring.

one way...

select distinct c.* from -- gets distinct students.
(
-- Give me all of the students from summer
select distinct a.* from student_summer
union all
-- Now give me all of the students from spring
select distinct b.* from student_sprint
) c;
Mar 1 '06 #2

noone wrote:
ph**************@gmail.com wrote:
Is this how it's done?

INSERT INTO student (
(SELECT DISTINCT a.*
FROM student_spring a, student_summer b
WHERE a.unique_key != b.unique_key)\
UNION
(SELECT DISTINCT b.*
FROM student_summer b, student_spring a
WHERE b.unique_key != a.unique_key)
)

I'm trying this but I keep losing data whenever I run this!

Also, how do I populate a database table from an XML file?

Thanx
Phil

I am guessing that student_summer and student_spring tables are
identical


[snip]

Sorry they weren't identical after all, there were some mysteriously
added new columns and changed datataypes, my query works now!

Now the next one doesn't :(

Phil

Mar 1 '06 #3
<ph**************@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Sorry they weren't identical after all, there were some mysteriously
added new columns and changed datataypes, my query works now!


This is a good illustration of why it's not a good practice to use * in
queries. When the columns change in number or order, queries such as your
union get broken.

A similar thing happens with insert statements when you don't list the
fields to insert into.
For example:
insert into mytable values (1, 2, 3) -- what happens when someone adds a
fourth field to mytable?

Regards,
Bill K.
Mar 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
9
by: Joost Kraaijeveld | last post by:
Hi all, I have 1 database that is required for several applications (the data must be shared ). They also have there own database. Is it possible to combine 2 databases into 1 database in DB2...
2
by: Reidar Jorgensen | last post by:
I have several Access databases, identical in structure, but different data. Is there an easy way to combine them all into one database? There are six tables, I just want the data from all...
17
by: Wilfried | last post by:
Hi, I have 5 tables: main data1
5
by: jhutchings | last post by:
Hello everyone, I have a database where I collect shipment data from various tables. However, I have a problem. Whenever I want to see shipping data for orders that were set to ship on or before...
1
by: Lars E. | last post by:
Hi all. I am trying to combine data from 2 tables in one datagridview. I have tables: "Customer" and "CustomerContact". I want to display Customer information (displaying all fields in...
2
by: drurjen | last post by:
Good morning. I am importing an XLS file into one of my tables. The fields are: Date Id Time IO 12/22/2006 2 12:48:45 PM 9 12/22/2006 16 5:40:55 AM 1 12/22/2006 16 12:03:59 PM 2 ...
5
by: Rodjk #613 | last post by:
Hello, I am working with a database that is in use in several locations. The structure of the databases are identical, but the data is different. I am tasked with combining the data into one...
6
by: Ryan Liu | last post by:
Hi, If I want to uniquely identify a computer. I can read CPU ID or Mac Address. I heard, but is this true: some BIOS can block CPU ID from being read? (In this case, will I get an exception,...
3
by: Al Reid | last post by:
I need a way to uniquely identify the machine, IP Address or user that called a web service. We are attempting to loosely integrate two applications where both apps, running on a single machine,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.