dreeves wrote:No problem. There are many columns in the table, but I only need two or three.
Code: Select all
Table1
Date Date
Requirement DECIMAL
Reimbursement DECIMAL
TABLE2
Date Date
Contribution DECIMAL
I've been trying UNION, but it seems to want the same number of columns from each table, is there a way around that?
That doesn't look like related data to me. Usually each transaction would be identified to an account number or something. Possibly all transactions in both tables relate to the same account?? If that's the case, they should probably all be in one table to begin with. The problem you are experiencing is due to the fact that the data is not organized in a logical way, or so it appears to me from the information you have provided. Relational databases must be organized in accordance with very strict rules of data normalization, or they won't work. Each table in a relational database relates to an
entity, which can be clearly defined as a collection of people, places, things, events, transactions, etc. So the first step in designing (or in troubleshooting) a database is to define what entities are represented. It appears that both your tables represent some kind of transactions. Then, if your purpose is to show ALL transactions in Date order, you must either combine them into one table or use a Union query. There are no other options.
Yes, Union queries must draw data from symmetrical sources; same number of columns, same data types and sizes. You could do something like this:
Code: Select all
SELECT A.Date AS Udate, A.Requirement AS Ureq, A.Reimbursement AS Ureimb, 0.00 AS Ucontr FROM Table1 A
UNION SELECT B.Date AS Udate, B.Contribution AS Ucontr, 0.00 AS Ureq, 0.00 AS Ureimb FROM TABLE2 B
ORDER BY Udate
http://dev.mysql.com/doc/refman/5.0/en/union.html
You should avoid using a Reserved Word like "Date" as a field name. It will cause you no end of trouble.