Merging Two Queries in Access with Common Keys and Different Totals












0















I have two queries that I have set up that have all the same fields except the totals. I am wanting the result to have the all the same fields as the original queries, but I want to have 2 total columns (Supplies purchased and supplies used) i.e. If all the codes were the same for each query except amount then the first record in the new query would have the amount purchased and used side by side.



I tried to link them with a join and I ended up getting duplicate values and other abnormalities which made the totals very high. I also tried a union of all the fields except for the sum columns. I then did a query off of that and the original 2 queries doing a join that only took records matching the union query except for amount, but the results were still funny.



I'm not sure where I went wrong. These were the fields for the original queries.



Query 1



+------+-------+-------+-------+-------+-------+---------------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Purchased |
+------+-------+-------+-------+-------+-------+---------------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 10,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 20,000 |
+------+-------+-------+-------+-------+-------+---------------------------+


Query 2



+------+-------+-------+-------+-------+-------+----------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Used |
+------+-------+-------+-------+-------+-------+----------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 5,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 6,000 |
+------+-------+-------+-------+-------+-------+----------------------+









share|improve this question

























  • Can you include the expected result for your sample data?

    – Lee Mac
    Jan 29 at 22:41











  • You say “These were the fields for the original queries.”  I don’t understand what you mean.  What does your data (i.e., your table) look like?  What queries are you using?  What results are you getting?  And, as Lee Mac asked, what result do you want? … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – Scott
    Jan 30 at 4:31


















0















I have two queries that I have set up that have all the same fields except the totals. I am wanting the result to have the all the same fields as the original queries, but I want to have 2 total columns (Supplies purchased and supplies used) i.e. If all the codes were the same for each query except amount then the first record in the new query would have the amount purchased and used side by side.



I tried to link them with a join and I ended up getting duplicate values and other abnormalities which made the totals very high. I also tried a union of all the fields except for the sum columns. I then did a query off of that and the original 2 queries doing a join that only took records matching the union query except for amount, but the results were still funny.



I'm not sure where I went wrong. These were the fields for the original queries.



Query 1



+------+-------+-------+-------+-------+-------+---------------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Purchased |
+------+-------+-------+-------+-------+-------+---------------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 10,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 20,000 |
+------+-------+-------+-------+-------+-------+---------------------------+


Query 2



+------+-------+-------+-------+-------+-------+----------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Used |
+------+-------+-------+-------+-------+-------+----------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 5,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 6,000 |
+------+-------+-------+-------+-------+-------+----------------------+









share|improve this question

























  • Can you include the expected result for your sample data?

    – Lee Mac
    Jan 29 at 22:41











  • You say “These were the fields for the original queries.”  I don’t understand what you mean.  What does your data (i.e., your table) look like?  What queries are you using?  What results are you getting?  And, as Lee Mac asked, what result do you want? … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – Scott
    Jan 30 at 4:31
















0












0








0








I have two queries that I have set up that have all the same fields except the totals. I am wanting the result to have the all the same fields as the original queries, but I want to have 2 total columns (Supplies purchased and supplies used) i.e. If all the codes were the same for each query except amount then the first record in the new query would have the amount purchased and used side by side.



I tried to link them with a join and I ended up getting duplicate values and other abnormalities which made the totals very high. I also tried a union of all the fields except for the sum columns. I then did a query off of that and the original 2 queries doing a join that only took records matching the union query except for amount, but the results were still funny.



I'm not sure where I went wrong. These were the fields for the original queries.



Query 1



+------+-------+-------+-------+-------+-------+---------------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Purchased |
+------+-------+-------+-------+-------+-------+---------------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 10,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 20,000 |
+------+-------+-------+-------+-------+-------+---------------------------+


Query 2



+------+-------+-------+-------+-------+-------+----------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Used |
+------+-------+-------+-------+-------+-------+----------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 5,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 6,000 |
+------+-------+-------+-------+-------+-------+----------------------+









share|improve this question
















I have two queries that I have set up that have all the same fields except the totals. I am wanting the result to have the all the same fields as the original queries, but I want to have 2 total columns (Supplies purchased and supplies used) i.e. If all the codes were the same for each query except amount then the first record in the new query would have the amount purchased and used side by side.



I tried to link them with a join and I ended up getting duplicate values and other abnormalities which made the totals very high. I also tried a union of all the fields except for the sum columns. I then did a query off of that and the original 2 queries doing a join that only took records matching the union query except for amount, but the results were still funny.



I'm not sure where I went wrong. These were the fields for the original queries.



Query 1



+------+-------+-------+-------+-------+-------+---------------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Purchased |
+------+-------+-------+-------+-------+-------+---------------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 10,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 20,000 |
+------+-------+-------+-------+-------+-------+---------------------------+


Query 2



+------+-------+-------+-------+-------+-------+----------------------+
| Year | Month | Code1 | Code2 | Code3 | Code4 | Sum of Supplies Used |
+------+-------+-------+-------+-------+-------+----------------------+
| 2003 | 01 | 123 | 123 | 123 | 123 | 5,000 |
| 2003 | 02 | 124 | 123 | 123 | 123 | 6,000 |
+------+-------+-------+-------+-------+-------+----------------------+






microsoft-access






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 29 at 23:23









Lee Mac

432212




432212










asked Jan 29 at 0:54









JuvicJuvic

11




11













  • Can you include the expected result for your sample data?

    – Lee Mac
    Jan 29 at 22:41











  • You say “These were the fields for the original queries.”  I don’t understand what you mean.  What does your data (i.e., your table) look like?  What queries are you using?  What results are you getting?  And, as Lee Mac asked, what result do you want? … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – Scott
    Jan 30 at 4:31





















  • Can you include the expected result for your sample data?

    – Lee Mac
    Jan 29 at 22:41











  • You say “These were the fields for the original queries.”  I don’t understand what you mean.  What does your data (i.e., your table) look like?  What queries are you using?  What results are you getting?  And, as Lee Mac asked, what result do you want? … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

    – Scott
    Jan 30 at 4:31



















Can you include the expected result for your sample data?

– Lee Mac
Jan 29 at 22:41





Can you include the expected result for your sample data?

– Lee Mac
Jan 29 at 22:41













You say “These were the fields for the original queries.”  I don’t understand what you mean.  What does your data (i.e., your table) look like?  What queries are you using?  What results are you getting?  And, as Lee Mac asked, what result do you want? … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

– Scott
Jan 30 at 4:31







You say “These were the fields for the original queries.”  I don’t understand what you mean.  What does your data (i.e., your table) look like?  What queries are you using?  What results are you getting?  And, as Lee Mac asked, what result do you want? … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.

– Scott
Jan 30 at 4:31












0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1399472%2fmerging-two-queries-in-access-with-common-keys-and-different-totals%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1399472%2fmerging-two-queries-in-access-with-common-keys-and-different-totals%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mouse cursor on multiple screens with different PPI

Agildo Ribeiro

Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”