SQL - Union select issue, results are not described properly
My Union Select statement works, but the results are on top of each other.
SQL Statement:
SELECT Cust_ID, Cust_FirstName, Cust_LastName
FROM kmsrutge_xoxoxo.Customers
UNION
SELECT Item_Type, Quantity, Total_Amount
FROM kmsrutge_xoxoxo.Invoices
WHERE Total_Amount >= '$5.00'
mysql sql union
add a comment |
My Union Select statement works, but the results are on top of each other.
SQL Statement:
SELECT Cust_ID, Cust_FirstName, Cust_LastName
FROM kmsrutge_xoxoxo.Customers
UNION
SELECT Item_Type, Quantity, Total_Amount
FROM kmsrutge_xoxoxo.Invoices
WHERE Total_Amount >= '$5.00'
mysql sql union
1
What are you mixing column data types which are not the same? I don't see any clean way to alter your query to make the result sensible.
– Tim Biegeleisen
Nov 6 '18 at 14:02
3
What is the question?
– Caleth
Nov 6 '18 at 14:02
I need the bottom column data to the right with the table names.
– katelynn767
Nov 6 '18 at 14:32
"I need the bottom column data to the right with the table names" I have a feeling you want a pivoting query stackoverflow.com/questions/7674786/mysql-pivot-table ... but hard to say for sure without example data and expected output.. i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…
– Raymond Nijland
Nov 6 '18 at 14:45
From the title of your question: "results are not described properly". The query is returning exactly what you're telling it to. If you need different results, you'll have to change your query accordingly. As others have said, we can help you only if you provide the minimum necessary information. Also, please clarify theTotal_Amount
field of yourInvoices
table: Is this aVARCHAR
field? If you're storing price information, this needs to be aDECIMAL
-type field.
– Zack
Nov 6 '18 at 16:11
add a comment |
My Union Select statement works, but the results are on top of each other.
SQL Statement:
SELECT Cust_ID, Cust_FirstName, Cust_LastName
FROM kmsrutge_xoxoxo.Customers
UNION
SELECT Item_Type, Quantity, Total_Amount
FROM kmsrutge_xoxoxo.Invoices
WHERE Total_Amount >= '$5.00'
mysql sql union
My Union Select statement works, but the results are on top of each other.
SQL Statement:
SELECT Cust_ID, Cust_FirstName, Cust_LastName
FROM kmsrutge_xoxoxo.Customers
UNION
SELECT Item_Type, Quantity, Total_Amount
FROM kmsrutge_xoxoxo.Invoices
WHERE Total_Amount >= '$5.00'
mysql sql union
mysql sql union
edited Nov 14 '18 at 14:59
Al Fahad
725821
725821
asked Nov 6 '18 at 13:58
katelynn767katelynn767
112
112
1
What are you mixing column data types which are not the same? I don't see any clean way to alter your query to make the result sensible.
– Tim Biegeleisen
Nov 6 '18 at 14:02
3
What is the question?
– Caleth
Nov 6 '18 at 14:02
I need the bottom column data to the right with the table names.
– katelynn767
Nov 6 '18 at 14:32
"I need the bottom column data to the right with the table names" I have a feeling you want a pivoting query stackoverflow.com/questions/7674786/mysql-pivot-table ... but hard to say for sure without example data and expected output.. i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…
– Raymond Nijland
Nov 6 '18 at 14:45
From the title of your question: "results are not described properly". The query is returning exactly what you're telling it to. If you need different results, you'll have to change your query accordingly. As others have said, we can help you only if you provide the minimum necessary information. Also, please clarify theTotal_Amount
field of yourInvoices
table: Is this aVARCHAR
field? If you're storing price information, this needs to be aDECIMAL
-type field.
– Zack
Nov 6 '18 at 16:11
add a comment |
1
What are you mixing column data types which are not the same? I don't see any clean way to alter your query to make the result sensible.
– Tim Biegeleisen
Nov 6 '18 at 14:02
3
What is the question?
– Caleth
Nov 6 '18 at 14:02
I need the bottom column data to the right with the table names.
– katelynn767
Nov 6 '18 at 14:32
"I need the bottom column data to the right with the table names" I have a feeling you want a pivoting query stackoverflow.com/questions/7674786/mysql-pivot-table ... but hard to say for sure without example data and expected output.. i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…
– Raymond Nijland
Nov 6 '18 at 14:45
From the title of your question: "results are not described properly". The query is returning exactly what you're telling it to. If you need different results, you'll have to change your query accordingly. As others have said, we can help you only if you provide the minimum necessary information. Also, please clarify theTotal_Amount
field of yourInvoices
table: Is this aVARCHAR
field? If you're storing price information, this needs to be aDECIMAL
-type field.
– Zack
Nov 6 '18 at 16:11
1
1
What are you mixing column data types which are not the same? I don't see any clean way to alter your query to make the result sensible.
– Tim Biegeleisen
Nov 6 '18 at 14:02
What are you mixing column data types which are not the same? I don't see any clean way to alter your query to make the result sensible.
– Tim Biegeleisen
Nov 6 '18 at 14:02
3
3
What is the question?
– Caleth
Nov 6 '18 at 14:02
What is the question?
– Caleth
Nov 6 '18 at 14:02
I need the bottom column data to the right with the table names.
– katelynn767
Nov 6 '18 at 14:32
I need the bottom column data to the right with the table names.
– katelynn767
Nov 6 '18 at 14:32
"I need the bottom column data to the right with the table names" I have a feeling you want a pivoting query stackoverflow.com/questions/7674786/mysql-pivot-table ... but hard to say for sure without example data and expected output.. i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…
– Raymond Nijland
Nov 6 '18 at 14:45
"I need the bottom column data to the right with the table names" I have a feeling you want a pivoting query stackoverflow.com/questions/7674786/mysql-pivot-table ... but hard to say for sure without example data and expected output.. i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…
– Raymond Nijland
Nov 6 '18 at 14:45
From the title of your question: "results are not described properly". The query is returning exactly what you're telling it to. If you need different results, you'll have to change your query accordingly. As others have said, we can help you only if you provide the minimum necessary information. Also, please clarify the
Total_Amount
field of your Invoices
table: Is this a VARCHAR
field? If you're storing price information, this needs to be a DECIMAL
-type field.– Zack
Nov 6 '18 at 16:11
From the title of your question: "results are not described properly". The query is returning exactly what you're telling it to. If you need different results, you'll have to change your query accordingly. As others have said, we can help you only if you provide the minimum necessary information. Also, please clarify the
Total_Amount
field of your Invoices
table: Is this a VARCHAR
field? If you're storing price information, this needs to be a DECIMAL
-type field.– Zack
Nov 6 '18 at 16:11
add a comment |
1 Answer
1
active
oldest
votes
You should pick (select) at least one column that is the same of both tables, and make a join statement per that column in order to get desired result.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53173394%2fsql-union-select-issue-results-are-not-described-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should pick (select) at least one column that is the same of both tables, and make a join statement per that column in order to get desired result.
add a comment |
You should pick (select) at least one column that is the same of both tables, and make a join statement per that column in order to get desired result.
add a comment |
You should pick (select) at least one column that is the same of both tables, and make a join statement per that column in order to get desired result.
You should pick (select) at least one column that is the same of both tables, and make a join statement per that column in order to get desired result.
answered Nov 6 '18 at 14:07
Andrija_GrozdanovicAndrija_Grozdanovic
33
33
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53173394%2fsql-union-select-issue-results-are-not-described-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
What are you mixing column data types which are not the same? I don't see any clean way to alter your query to make the result sensible.
– Tim Biegeleisen
Nov 6 '18 at 14:02
3
What is the question?
– Caleth
Nov 6 '18 at 14:02
I need the bottom column data to the right with the table names.
– katelynn767
Nov 6 '18 at 14:32
"I need the bottom column data to the right with the table names" I have a feeling you want a pivoting query stackoverflow.com/questions/7674786/mysql-pivot-table ... but hard to say for sure without example data and expected output.. i advice you to read this "Why should I provide an MCVE for what seems to me to be a very simple SQL query?" meta.stackoverflow.com/questions/333952/…
– Raymond Nijland
Nov 6 '18 at 14:45
From the title of your question: "results are not described properly". The query is returning exactly what you're telling it to. If you need different results, you'll have to change your query accordingly. As others have said, we can help you only if you provide the minimum necessary information. Also, please clarify the
Total_Amount
field of yourInvoices
table: Is this aVARCHAR
field? If you're storing price information, this needs to be aDECIMAL
-type field.– Zack
Nov 6 '18 at 16:11