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

Union query

I am using Access 2K as a front end to a MYSQL database.

I am trying to run a Union query on the MYSQL database. The query is (much
simplified)
SELECT [faxid] as ID from faxdata UNION
SELECT [letid] as ID from letdata UNION
SELECT [memoid] as ID FROM MEMODATA;

I get an ODBC error. The same query runs when the backend files are MDB
files and it runs with MYSQL if I only combine 2 tables.
Is there some limit with MYSQL on being only able to use a UNION on 2
tables.
Alex
Jul 23 '05 #1
3 3529
On Fri, 28 Jan 2005 14:16:56 GMT, in mailing.database.mysql "Paradigm"
<al********@hotmail.com> wrote:
| I am using Access 2K as a front end to a MYSQL database.
|
| I am trying to run a Union query on the MYSQL database. The query is (much
| simplified)
| SELECT [faxid] as ID from faxdata UNION
| SELECT [letid] as ID from letdata UNION
| SELECT [memoid] as ID FROM MEMODATA;
|
| I get an ODBC error. The same query runs when the backend files are MDB
| files and it runs with MYSQL if I only combine 2 tables.
| Is there some limit with MYSQL on being only able to use a UNION on 2
| tables.


Each select statement in a union query must return the same number of
columns and the same data type for each column. If your first select
statement returns 3 fields (int, char, blob) then so must the other
select statements.

If any table is returning more columns than the first select statement
then you'll need to add (as I call them) virtual fields (f3 in the
following example)
select f1, f2, 0 as f3 from t1 union
select f1, f2, f3 from t2 union
select f1, f2, 0 as f3 from t3

http://dev.mysql.com/doc/mysql/en/union.html

---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #2
I have made sure that the column numbers and types are the same. I have 4
tables that I want to UNION into a single query. I simplified this below
into 3 tables and a single field. The example does not work. I can reduce
the example to any 2 of the tables and it then does work. The ID field here
is an int(11) auto_increment type in MYSQL and was an Autonumber field in
Acces.
I am converting an Access application into a MYSQL backend. The same query
works if the tables are MDB tables but not if they are MYSQL tables.
Alex

SELECT [faxid] as ID from faxdata UNION
SELECT [letid] as ID from letdata UNION
SELECT [memoid] as ID FROM MEMODATA;

"Jeff North" <jn****@bigpond.net.au> wrote in message
news:v7********************************@4ax.com...
On Fri, 28 Jan 2005 14:16:56 GMT, in mailing.database.mysql "Paradigm"
<al********@hotmail.com> wrote:
| I am using Access 2K as a front end to a MYSQL database.
|
| I am trying to run a Union query on the MYSQL database. The query is (much| simplified)
| SELECT [faxid] as ID from faxdata UNION
| SELECT [letid] as ID from letdata UNION
| SELECT [memoid] as ID FROM MEMODATA;
|
| I get an ODBC error. The same query runs when the backend files are MDB
| files and it runs with MYSQL if I only combine 2 tables.
| Is there some limit with MYSQL on being only able to use a UNION on 2
| tables.


Each select statement in a union query must return the same number of
columns and the same data type for each column. If your first select
statement returns 3 fields (int, char, blob) then so must the other
select statements.

If any table is returning more columns than the first select statement
then you'll need to add (as I call them) virtual fields (f3 in the
following example)
select f1, f2, 0 as f3 from t1 union
select f1, f2, f3 from t2 union
select f1, f2, 0 as f3 from t3

http://dev.mysql.com/doc/mysql/en/union.html

---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------

Jul 23 '05 #3
On Sat, 29 Jan 2005 10:05:28 GMT, in mailing.database.mysql "Paradigm"
<al********@hotmail.com> wrote:
| I have made sure that the column numbers and types are the same. I have 4
| tables that I want to UNION into a single query. I simplified this below
| into 3 tables and a single field. The example does not work. I can reduce
| the example to any 2 of the tables and it then does work. The ID field here
| is an int(11) auto_increment type in MYSQL and was an Autonumber field in
| Acces.
| I am converting an Access application into a MYSQL backend. The same query
| works if the tables are MDB tables but not if they are MYSQL tables.
| Alex
|
| SELECT [faxid] as ID from faxdata UNION
| SELECT [letid] as ID from letdata UNION
| SELECT [memoid] as ID FROM MEMODATA;
[Kicking myself for missing the obvious]
Remove the square brackets from the field names, they are an Access
thing.
| "Jeff North" <jn****@bigpond.net.au> wrote in message
| news:v7********************************@4ax.com...
| > On Fri, 28 Jan 2005 14:16:56 GMT, in mailing.database.mysql "Paradigm"
| > <al********@hotmail.com> wrote:
| >
| > >| I am using Access 2K as a front end to a MYSQL database.
| > >|
| > >| I am trying to run a Union query on the MYSQL database. The query is
| (much
| > >| simplified)
| > >| SELECT [faxid] as ID from faxdata UNION
| > >| SELECT [letid] as ID from letdata UNION
| > >| SELECT [memoid] as ID FROM MEMODATA;
| > >|
| > >| I get an ODBC error. The same query runs when the backend files are MDB
| > >| files and it runs with MYSQL if I only combine 2 tables.
| > >| Is there some limit with MYSQL on being only able to use a UNION on 2
| > >| tables.
| >
| > Each select statement in a union query must return the same number of
| > columns and the same data type for each column. If your first select
| > statement returns 3 fields (int, char, blob) then so must the other
| > select statements.
| >
| > If any table is returning more columns than the first select statement
| > then you'll need to add (as I call them) virtual fields (f3 in the
| > following example)
| > select f1, f2, 0 as f3 from t1 union
| > select f1, f2, f3 from t2 union
| > select f1, f2, 0 as f3 from t3
| >
| > http://dev.mysql.com/doc/mysql/en/union.html
| >
| > ---------------------------------------------------------------
| > jn******@yourpantsyahoo.com.au : Remove your pants to reply
| > ---------------------------------------------------------------
|


---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Jul 23 '05 #4

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

Similar topics

14
by: Salad | last post by:
A97. Situation: I have 3 tables with a text field in each and a date field in the first 2 tables: Table1 Text1, Date1 Table2 Text2, Date2 Table3 Text3 (no date field) The following...
5
by: Lyn | last post by:
This one is difficult to explain, so I will cut it down to the basics. I have a major table 'tblA' which has an autonum field 'ID-A' as primary key (of no significance to users). 'tblA' contains...
2
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code ...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
3
by: mikes | last post by:
I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are...
5
by: BillCo | last post by:
I'm having a problem with a union query, two simple queries joined with a union statement. It's created in code based on parameters. Users were noticing some inconsistant data and when I analysed...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
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
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: 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
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
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
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.