Newbie needs help on query (MYSQL)











up vote
0
down vote

favorite












I'm new here and nearly new in SQL.



My problem:
I've a table (T1) with



Datetime, CostNo, Amount



second table (T2) with



Date, CostNo, BillNo



In the query should be



Date, CostNo, BillNo, Amount



My problem are several BillNos for the same CostNo the same day.



I need a kind of sorting the BillNo according to the Datetime.



T1 f.e.:



2018-11-02 11:14:52 3637    24.10  
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00


T2 f.e.:



2018-11-02  3637    26189  
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196


so my query:



select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate


works fine until CostNo 2552:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00


This should be the result:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00









share|improve this question




















  • 3




    Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Madhur Bhaiya
    Nov 21 at 9:30






  • 4




    Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
    – ADyson
    Nov 21 at 9:33












  • Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
    – P.Salmon
    Nov 21 at 9:46










  • There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
    – P.Salmon
    Nov 21 at 10:05










  • Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
    – ADyson
    Nov 21 at 11:33

















up vote
0
down vote

favorite












I'm new here and nearly new in SQL.



My problem:
I've a table (T1) with



Datetime, CostNo, Amount



second table (T2) with



Date, CostNo, BillNo



In the query should be



Date, CostNo, BillNo, Amount



My problem are several BillNos for the same CostNo the same day.



I need a kind of sorting the BillNo according to the Datetime.



T1 f.e.:



2018-11-02 11:14:52 3637    24.10  
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00


T2 f.e.:



2018-11-02  3637    26189  
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196


so my query:



select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate


works fine until CostNo 2552:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00


This should be the result:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00









share|improve this question




















  • 3




    Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Madhur Bhaiya
    Nov 21 at 9:30






  • 4




    Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
    – ADyson
    Nov 21 at 9:33












  • Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
    – P.Salmon
    Nov 21 at 9:46










  • There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
    – P.Salmon
    Nov 21 at 10:05










  • Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
    – ADyson
    Nov 21 at 11:33















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm new here and nearly new in SQL.



My problem:
I've a table (T1) with



Datetime, CostNo, Amount



second table (T2) with



Date, CostNo, BillNo



In the query should be



Date, CostNo, BillNo, Amount



My problem are several BillNos for the same CostNo the same day.



I need a kind of sorting the BillNo according to the Datetime.



T1 f.e.:



2018-11-02 11:14:52 3637    24.10  
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00


T2 f.e.:



2018-11-02  3637    26189  
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196


so my query:



select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate


works fine until CostNo 2552:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00


This should be the result:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00









share|improve this question















I'm new here and nearly new in SQL.



My problem:
I've a table (T1) with



Datetime, CostNo, Amount



second table (T2) with



Date, CostNo, BillNo



In the query should be



Date, CostNo, BillNo, Amount



My problem are several BillNos for the same CostNo the same day.



I need a kind of sorting the BillNo according to the Datetime.



T1 f.e.:



2018-11-02 11:14:52 3637    24.10  
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00


T2 f.e.:



2018-11-02  3637    26189  
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196


so my query:



select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate


works fine until CostNo 2552:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00


This should be the result:



2018-11-02  3637    26189   24.10  
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00






mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 7:17

























asked Nov 21 at 9:30









Schnurze

11




11








  • 3




    Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Madhur Bhaiya
    Nov 21 at 9:30






  • 4




    Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
    – ADyson
    Nov 21 at 9:33












  • Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
    – P.Salmon
    Nov 21 at 9:46










  • There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
    – P.Salmon
    Nov 21 at 10:05










  • Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
    – ADyson
    Nov 21 at 11:33
















  • 3




    Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Madhur Bhaiya
    Nov 21 at 9:30






  • 4




    Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
    – ADyson
    Nov 21 at 9:33












  • Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
    – P.Salmon
    Nov 21 at 9:46










  • There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
    – P.Salmon
    Nov 21 at 10:05










  • Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
    – ADyson
    Nov 21 at 11:33










3




3




Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30




Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30




4




4




Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33






Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33














Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46




Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46












There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05




There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05












Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33






Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33














2 Answers
2






active

oldest

votes

















up vote
1
down vote













I am guessing that you want:



select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
from `T2` join
`T1`
on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
order by T!.CostNo, T1.BillDateTime DESC;


First note the proper use of JOIN. Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.



Second, if you want the results in a particular order, then your query should have an ORDER BY clause. SQL tables and result sets (with no ORDER BY) represent unordered sets. So, you need an ORDER BY. I am guessing you want to keep all the CostNos together, and then within each, ordered by the date/time.






share|improve this answer





















  • OK, another code, looks good or even better then mine, but didn't solve the problem.
    – Schnurze
    Nov 22 at 7:22


















up vote
0
down vote













OK thanks for the help. I found a solution by myself.
Here it is, if someone will know it:
The BillNo from the 2. table is linked to the DateTime of table 1
So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
Next I build a temporary table from table 2, order by BillNo and add a row ID.
Now I can do a query with T1.ID = T2.ID and that's it.



Feel free to post a better and/or shorter solution.






share|improve this answer








New contributor




Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















    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',
    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%2fstackoverflow.com%2fquestions%2f53408925%2fnewbie-needs-help-on-query-mysql%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    I am guessing that you want:



    select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
    from `T2` join
    `T1`
    on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
    order by T!.CostNo, T1.BillDateTime DESC;


    First note the proper use of JOIN. Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.



    Second, if you want the results in a particular order, then your query should have an ORDER BY clause. SQL tables and result sets (with no ORDER BY) represent unordered sets. So, you need an ORDER BY. I am guessing you want to keep all the CostNos together, and then within each, ordered by the date/time.






    share|improve this answer





















    • OK, another code, looks good or even better then mine, but didn't solve the problem.
      – Schnurze
      Nov 22 at 7:22















    up vote
    1
    down vote













    I am guessing that you want:



    select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
    from `T2` join
    `T1`
    on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
    order by T!.CostNo, T1.BillDateTime DESC;


    First note the proper use of JOIN. Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.



    Second, if you want the results in a particular order, then your query should have an ORDER BY clause. SQL tables and result sets (with no ORDER BY) represent unordered sets. So, you need an ORDER BY. I am guessing you want to keep all the CostNos together, and then within each, ordered by the date/time.






    share|improve this answer





















    • OK, another code, looks good or even better then mine, but didn't solve the problem.
      – Schnurze
      Nov 22 at 7:22













    up vote
    1
    down vote










    up vote
    1
    down vote









    I am guessing that you want:



    select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
    from `T2` join
    `T1`
    on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
    order by T!.CostNo, T1.BillDateTime DESC;


    First note the proper use of JOIN. Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.



    Second, if you want the results in a particular order, then your query should have an ORDER BY clause. SQL tables and result sets (with no ORDER BY) represent unordered sets. So, you need an ORDER BY. I am guessing you want to keep all the CostNos together, and then within each, ordered by the date/time.






    share|improve this answer












    I am guessing that you want:



    select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
    from `T2` join
    `T1`
    on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
    order by T!.CostNo, T1.BillDateTime DESC;


    First note the proper use of JOIN. Never use commas in the FROM clause. Always use proper, explicit, standard JOIN syntax.



    Second, if you want the results in a particular order, then your query should have an ORDER BY clause. SQL tables and result sets (with no ORDER BY) represent unordered sets. So, you need an ORDER BY. I am guessing you want to keep all the CostNos together, and then within each, ordered by the date/time.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 at 11:57









    Gordon Linoff

    747k34285390




    747k34285390












    • OK, another code, looks good or even better then mine, but didn't solve the problem.
      – Schnurze
      Nov 22 at 7:22


















    • OK, another code, looks good or even better then mine, but didn't solve the problem.
      – Schnurze
      Nov 22 at 7:22
















    OK, another code, looks good or even better then mine, but didn't solve the problem.
    – Schnurze
    Nov 22 at 7:22




    OK, another code, looks good or even better then mine, but didn't solve the problem.
    – Schnurze
    Nov 22 at 7:22












    up vote
    0
    down vote













    OK thanks for the help. I found a solution by myself.
    Here it is, if someone will know it:
    The BillNo from the 2. table is linked to the DateTime of table 1
    So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
    Next I build a temporary table from table 2, order by BillNo and add a row ID.
    Now I can do a query with T1.ID = T2.ID and that's it.



    Feel free to post a better and/or shorter solution.






    share|improve this answer








    New contributor




    Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote













      OK thanks for the help. I found a solution by myself.
      Here it is, if someone will know it:
      The BillNo from the 2. table is linked to the DateTime of table 1
      So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
      Next I build a temporary table from table 2, order by BillNo and add a row ID.
      Now I can do a query with T1.ID = T2.ID and that's it.



      Feel free to post a better and/or shorter solution.






      share|improve this answer








      New contributor




      Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        0
        down vote










        up vote
        0
        down vote









        OK thanks for the help. I found a solution by myself.
        Here it is, if someone will know it:
        The BillNo from the 2. table is linked to the DateTime of table 1
        So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
        Next I build a temporary table from table 2, order by BillNo and add a row ID.
        Now I can do a query with T1.ID = T2.ID and that's it.



        Feel free to post a better and/or shorter solution.






        share|improve this answer








        New contributor




        Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        OK thanks for the help. I found a solution by myself.
        Here it is, if someone will know it:
        The BillNo from the 2. table is linked to the DateTime of table 1
        So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
        Next I build a temporary table from table 2, order by BillNo and add a row ID.
        Now I can do a query with T1.ID = T2.ID and that's it.



        Feel free to post a better and/or shorter solution.







        share|improve this answer








        New contributor




        Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Nov 23 at 11:20









        Schnurze

        11




        11




        New contributor




        Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Schnurze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            draft saved

            draft discarded




















































            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2fstackoverflow.com%2fquestions%2f53408925%2fnewbie-needs-help-on-query-mysql%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

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...