MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't
ask)
I have database Spring with table Students
I have database Summer with table Students
I am tasked to produce a query of all students in both tables with no
duplicates. No clue whatsoever.
I'm thinking an INTERSECT followed by 2 UNION SELECT statements, but
how far off am I? The tables are absolutely identical in every way
including indexes; the data MIGHT be identical (same data might be in
Spring.Students and Summer.Students ), however, that won't always be the
case. The column Spring.Students .id will not share the same value as
Summer.Students .id as data can be entered within separate sequences
even if the data in both tables is absolutely identical.
Am I on the right track with INTERSECT/UNION or what do you recommend?
Thanx
Phil 48 3873 ph************* *@gmail.com wrote: MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask)
I have database Spring with table Students
I have database Summer with table Students
I am tasked to produce a query of all students in both tables with no duplicates. No clue whatsoever.
I'm thinking an INTERSECT followed by 2 UNION SELECT statements, but how far off am I? The tables are absolutely identical in every way including indexes; the data MIGHT be identical (same data might be in Spring.Students and Summer.Students ), however, that won't always be the case. The column Spring.Students .id will not share the same value as Summer.Students .id as data can be entered within separate sequences even if the data in both tables is absolutely identical.
Am I on the right track with INTERSECT/UNION or what do you recommend?
Thanx Phil
Well, this would be easier if you had both tables in one database. I
think it's more straightforward and portable to compare tables that
exist in the same database.
If necessary, create a third database and copy the Student tables from
Spring and Summer into the third database. You can use the mysqldump
tool to create a backup of a single table from each, then edit the two
dump files with a text editor to make sure the table names will be
distinct, then restore both dumps to the third database.
Here's one query to get the set of all students. Get all students who
exist in both Spring and Summer, then all students only in Spring, then
all students only in Summer. These three sets have no overlap.
(SELECT S1.student
FROM Spring AS S1 INNER JOIN Summer AS U1 ON S1.student = U1.student)
UNION
(SELECT S2.student
FROM Spring AS S2 LEFT OUTER JOIN Summer AS U2 ON S2.student = U2.student
WHERE U2.student IS NULL)
UNION
(SELECT U3.student
FROM Spring AS S3 RIGHT OUTER JOIN Summer AS U3 ON S3.student = U3.student
WHERE S3.student IS NULL)
ORDER BY student;
Regards,
Bill K.
The right thing is to use a UNION join:
select * from Spring.Students
union
select * from Summer.Students
Markus
Unfortunately that choice produced a MySQL syntax error.. I should have
mentioned we're using MySQL 3.23.58 in the current version and will
hopefully be upgrading to MySQL 4.0+ in the new version next year
Phil
Markus Popp wrote: The right thing is to use a UNION join:
select * from Spring.Students union select * from Summer.Students
Markus
See below, thanx
Bill Karwin wrote: ph************* *@gmail.com wrote: MySQL 3.23.58 - 4.0.17 (yep, several database server instances, don't ask)
I have database Spring with table Students
I have database Summer with table Students
I am tasked to produce a query of all students in both tables with no duplicates. No clue whatsoever.
I'm thinking an INTERSECT followed by 2 UNION SELECT statements, but how far off am I? The tables are absolutely identical in every way including indexes; the data MIGHT be identical (same data might be in Spring.Students and Summer.Students ), however, that won't always be the case. The column Spring.Students .id will not share the same value as Summer.Students .id as data can be entered within separate sequences even if the data in both tables is absolutely identical.
Am I on the right track with INTERSECT/UNION or what do you recommend?
Thanx Phil
Well, this would be easier if you had both tables in one database. I think it's more straightforward and portable to compare tables that exist in the same database.
Sadly, that is not an option. The client requested they be put into
separate databases. The explanation was about as "non-techie" as it
gets so I'll just spare you, but they plan to "rejoin" the tables into
one table in the new version of the application next year
If necessary, create a third database and copy the Student tables from Spring and Summer into the third database. You can use the mysqldump tool to create a backup of a single table from each, then edit the two dump files with a text editor to make sure the table names will be distinct, then restore both dumps to the third database.
The only problem with this approach is that the separate databases are
being currently used right now in a series of web application "patch"
scripts that were written in the zero-hour to placate the customer's
need to see the students separated by "spring" and "summer", so I
cannot yet rejoin them until the customer blesses the workflow
methodology of the updated web application, which won't be until next
year..
Here's one query to get the set of all students. Get all students who exist in both Spring and Summer, then all students only in Spring, then all students only in Summer. These three sets have no overlap.
(SELECT S1.student FROM Spring AS S1 INNER JOIN Summer AS U1 ON S1.student = U1.student) UNION (SELECT S2.student FROM Spring AS S2 LEFT OUTER JOIN Summer AS U2 ON S2.student = U2.student WHERE U2.student IS NULL) UNION (SELECT U3.student FROM Spring AS S3 RIGHT OUTER JOIN Summer AS U3 ON S3.student = U3.student WHERE S3.student IS NULL) ORDER BY student;
Yeah I tried the UNION statement but it failed due to a MySQL syntax
error. I forgot to mention that we're using MySQL 3.23.58 right now
and upgrading is "not an option at this time" (yep, next year.. blah
blah blah)
Regards, Bill K.
*sigh* Can't use UNION so don't know what to do at this point
Phil
Ok, after re-reading (and getting my second cup of coffee) my brain
just kicked into gear and realized what you just said. In short, Phil
has left <stupid&g t; mode.
That sounds doable, however, I will have to work on the means of
ensuring that the data from Spring.Students doesn't produce dups with
Summer.Students , and because UNION is not supported in MySQL 3.23.58
(I've tried to use it and consistently got syntax errors), I have
absolutely no idea how to do this :(
Phil
Bill Karwin wrote: If necessary, create a third database and copy the Student tables from Spring and Summer into the third database. You can use the mysqldump tool to create a backup of a single table from each, then edit the two dump files with a text editor to make sure the table names will be distinct, then restore both dumps to the third database.
Incidentally, I tried your query, and, unfortunately, it produces a
syntax error in MySQL 3.23.58, which is really unfortunate considering
it's the easiest way to do this, and, at this point, don't have any
alternatives. :(
Phil
Bill Karwin wrote: (SELECT S1.student FROM Spring AS S1 INNER JOIN Summer AS U1 ON S1.student = U1.student) UNION (SELECT S2.student FROM Spring AS S2 LEFT OUTER JOIN Summer AS U2 ON S2.student = U2.student WHERE U2.student IS NULL) UNION (SELECT U3.student FROM Spring AS S3 RIGHT OUTER JOIN Summer AS U3 ON S3.student = U3.student WHERE S3.student IS NULL) ORDER BY student;
Regards, Bill K.
I'm afraid, it's not possible to do this with MySQL 3.23. You could only
query the tables separately and combine them on the client side.
If you consider updating (in fact, it's certainly a good choice to update),
I would recommand that you update straight to 5.0.x. Of course, there are
many details to take care of, but the manual stresses everything you need to
know to update from each release to another.
Markus
Hold on - there's one thing I forgot, there maybe is a solution.
If you use MyISAM tables you can use MERGE tables to combine 2 tables which
are identical in its structure. I'm not absolutely sure if MERGE tables are
supported in MySQL 3.23 (but I think so) and if it's possible to combine 2
tables that are in different databases. But in general, it works like this:
create table table_name ([column_definiti on as in the tables]) engine=merge
union=(table1, table2, ...)
Then this new table holds all records that are in each of the tables and you
can query them together.
Markus
Hmm.. I had no idea about that one, but this worked for me:
CREATE TABLE blah SELECT DISTINCT s.* FROM db1.table1 s LEFT OUTER JOIN
db2.table1 u WHERE lower(s.first_n ame) <> lower(u.first_n ame) AND
lower(s.last_na me) <> lower(u.last_na me)
Phil
Markus Popp wrote: Hold on - there's one thing I forgot, there maybe is a solution.
If you use MyISAM tables you can use MERGE tables to combine 2 tables which are identical in its structure. I'm not absolutely sure if MERGE tables are supported in MySQL 3.23 (but I think so) and if it's possible to combine 2 tables that are in different databases. But in general, it works like this:
create table table_name ([column_definiti on as in the tables]) engine=merge union=(table1, table2, ...)
Then this new table holds all records that are in each of the tables and you can query them together.
Markus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scotter |
last post by:
Okay I think my title line was worded misleadingly. So here goes again.
I've got quite 20 identical MDB files running on an IIS5 server.
From time to time I need to go into various tables and add a field or two.
It would be great if there were an application out there that could either:
(a) sync all MDB designs (and/or data) designated to match one I've added
some fields/tables to
OR
(b) go into all designated MDBs and create new...
|
by: Andreas Lauffer |
last post by:
I changed from Access97 to AccessXP and I have immense performance
problems.
Details:
- Access XP MDB with Jet 4.0 ( no ADP-Project )
- Linked Tables to SQL-Server 2000 over ODBC
I used the SQL Profile to watch the T-SQL-Command which Access ( who
creates the commands?) creates and noticed:
|
by: James Fortune |
last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't
understand why people who know how to write code to completely replace
a front end do not write something that will automate the code that
implements managing unbound controls on forms given the superior
performance of unbound controls in a client/server environment. I can
easily understand a newbie using bound controls or someone with a
tight deadline. I guess I need...
|
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 databases merged into one database.
Thanks in advance.
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to
communicate with a MySQL database table on a web server, from inside
of my company's Access-VBA application. I know VBA pretty well but
have never before needed to do this HTTP/XML/MySQL type functions.
| |
by: Veeru71 |
last post by:
We have got 2 DB2-UDB databases (DB1 & DB2) running on separate
instances( Inst1 & Inst2).
DB1 has got Schema1 and DB2 has got Schema2.
We would like to setup some kind of replication to replicate both
Schema1 & Schema2 onto a 3 rd database (DB3) running on a 3 rd
instance (Inst3). This is basically to separate out Data Reads
(Reports module of the app) from the primary databases for performace
reasons. Also, Some of the Reports join...
|
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= |
last post by:
I get the above error in some of the ASP.NET web applications on a
server, and I need some help figuring out how to deal with it.
This is a rather long post, and I hope I have enough details that
someone who bothers to read all of it have some pointers.
Note, I have posted the stack trace and the code exhibiting the problem
further down so if you want to start by reading that, search for +++
Also note that I am unable to reproduce...
|
by: Okonita via DBMonster.com |
last post by:
Hi all,
I am comming along with all this Linus/DB2/scripting business...I am no
longer scared of it!! (LOL). But,
I need to create a .ksh script that does a REORGCHK and output only tables
recommended for reorg.
My goal is to reorgchk and run reorgs based on entries in this reorg file as
shown in the example below.
I have tried my hand at the following failing script and hope that gurus here
can throw me a lifeline of examples on how to...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |