Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should union both results and check rows for it like below :</p> <pre><code>select transaction_id, sum(order_id) as order_id, sum(payment_id) as payment_id from ( SELECT t.transaction_id, ROW_NUMBER() OVER (PARTITION BY t.transaction_id ORDER BY order_id) RowNo, o.order_id, null as payment_id FROM TRANSACTIONS t LEFT JOIN ORDERS o on o.transaction_id = t.transaction_id union SELECT t.transaction_id, ROW_NUMBER() OVER (PARTITION BY t.transaction_id ORDER BY payment_id) RowNo, null as order_id, p.payment_id FROM TRANSACTIONS t LEFT JOIN Payments p on p.transaction_id = t.transaction_id ) tt group by transaction_id, RowNo </code></pre> <p>SQL Fiddle Demo : <a href="http://sqlfiddle.com/#!3/e991d/21" rel="nofollow">http://sqlfiddle.com/#!3/e991d/21</a></p> <p><strong>UPDATE :</strong></p> <p>Please try it with JOIN instead of UNION like below :</p> <pre><code>SELECT t1.transaction_id, t1.order_id, t2.payment_id from ( SELECT t.transaction_id, ROW_NUMBER() OVER (PARTITION BY t.transaction_id ORDER BY order_id) RowNo, o.order_id FROM TRANSACTIONS t LEFT JOIN ORDERS o on o.transaction_id = t.transaction_id ) t1 full join ( SELECT t.transaction_id, ROW_NUMBER() OVER (PARTITION BY t.transaction_id ORDER BY p.payment_id) RowNo, p.payment_id FROM TRANSACTIONS t LEFT JOIN Payments p on p.transaction_id = t.transaction_id ) t2 on t1.transaction_id = t2.transaction_id and t1.RowNo = t2.RowNo </code></pre> <p>SQL Fiddle Demo : <a href="http://sqlfiddle.com/#!3/e991d/20" rel="nofollow">http://sqlfiddle.com/#!3/e991d/20</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload