Need help in select statement from two tables

Discussion in 'MySQL' started by newphpcoder, Sep 29, 2013.

  1. #1
    Hi,

    Good day!

    I have a problem in my select query statement to get the value of reject from op_reject table and spv_reject table in one row

    here is my query:
    SELECT o.compound_type, SUM(o.reject) AS op_reject, s.compound_type, SUM(s.reject) AS spv_reject
    FROM op_reject AS o ,spv_reject AS s
    WHERE o.compound_type = 'P28' AND s.compound_type = 'P28'
    AND o.process_id = '2' AND s.process_id = '2'
    AND o.reject_date = '2013-09-30' AND s.reject_date = '2013-09-30' 
    GROUP BY  o.compound_type, o.process_id;
    Code (markup):
    this code has an output:

    P28|6.00|P28|6.00

    but it should only be:

    P28|3.00|P28|3.00
    because the sum of rejects are only 3.00

    I attached my database for your reference.

    Any help is highly appreciated.

    Thank you so much.
     

    Attached Files:

    newphpcoder, Sep 29, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,830
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #2
    sarahk, Sep 30, 2013 IP