shacho
asked on
SQL for merging
If I have two tables that look like this:
TBL1
MON AMT
Jan 111
Feb 222
Mar 333
TBL2
MON AMT
Jan 555
Feb 666
Mar 777
what is the SQL I need to create this?
TBL3
MON AMT_1 AMT_2
Jan 111 555
Feb 222 666
Mar 333 777
Mike
TBL1
MON AMT
Jan 111
Feb 222
Mar 333
TBL2
MON AMT
Jan 555
Feb 666
Mar 777
what is the SQL I need to create this?
TBL3
MON AMT_1 AMT_2
Jan 111 555
Feb 222 666
Mar 333 777
Mike
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>The more appropriate question is why do you have two tables with identical structure?
In fact, there is only one table. The two "tables" I'm trying to merge are actually separate queries on the same table that yield different results for what I've called "AMT" in the post. What I'm trying to do is pair them up along the same time series so I can create a two-line graph showing how the results look on the same axes. There might be a better way to do this, but I don't have much experience with charts and this was all I could come up with. In any case, I did in fact achieve this with a Union query, and an aggregation query on top of that. Similar to what you've done with the Pivot. So based on everyone's input I'm satisfied that this is a decent approach.
>Is this question related to MS Access or MS SQL Server?
It's in Access, but the technique is generic enough, hence the cross post.
Thanks all for your help.
Cheers,
Mike
In fact, there is only one table. The two "tables" I'm trying to merge are actually separate queries on the same table that yield different results for what I've called "AMT" in the post. What I'm trying to do is pair them up along the same time series so I can create a two-line graph showing how the results look on the same axes. There might be a better way to do this, but I don't have much experience with charts and this was all I could come up with. In any case, I did in fact achieve this with a Union query, and an aggregation query on top of that. Similar to what you've done with the Pivot. So based on everyone's input I'm satisfied that this is a decent approach.
>Is this question related to MS Access or MS SQL Server?
It's in Access, but the technique is generic enough, hence the cross post.
Thanks all for your help.
Cheers,
Mike
>>It's in Access, but the technique is generic enough, hence the cross post.<<
That may be the case, but the SQL syntax is not the same. Besides if it was just a question of "technique", why stop with MS SQL Server? Why not add MySQL, Oracle, etc.?
That may be the case, but the SQL syntax is not the same. Besides if it was just a question of "technique", why stop with MS SQL Server? Why not add MySQL, Oracle, etc.?
ASKER
>That may be the case, but the SQL syntax is not the same.
Right, but with a generic technique you can usually "translate" from one dialect of SQL to another, if needed. Or do a web search on how to achieve something similar in your dialect of choice. This has helped me many times.
>Why stop with MS SQL Server? Why not add MySQL, Oracle, etc.?
It would indeed be nice if you could add more than 3 zones, but as far as I know you still can't.
MB
Right, but with a generic technique you can usually "translate" from one dialect of SQL to another, if needed. Or do a web search on how to achieve something similar in your dialect of choice. This has helped me many times.
>Why stop with MS SQL Server? Why not add MySQL, Oracle, etc.?
It would indeed be nice if you could add more than 3 zones, but as far as I know you still can't.
MB
ASKER
...and MS SQL Server uses SQL that is more similar to JET SQL than MySql and Oracle.
Is this question related to MS Access or MS SQL Server? The answer will be different in each case, so in most cases it is not appropriate to post in both zones as it only causes confusion and is a waste of time.