Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Its not very clear, but as far as I can think, what you want is to get the two results in a single query result. Try joining them on the basis of accountID from both the tables.AS:</p> <pre><code>SELECT * from (select accountID,COUNT(planters.todate) as count2date, SUM(planters.todate) as sum2date ----- -----) count_1 inner join (SELECT accountID,COUNT(planters.compdate) as countcomp, SUM(planters.compdate) as sumcomp ----- -----) count_2 using(accountID); </code></pre> <p>Do not use "AS" before count_1 or count_2. It is better to replace * in the outer select query with more specific attributes, like count_1.count2date or like.</p> <p>Hope this helps ! If anything else is what you are looking for, do let me know.</p> <p>-----UPDATE-----</p> <p>After looking at your file you uploaded, I came up with the following query:</p> <pre><code>SELECT count1.compmonth, IFNULL( todatecount, 0 ) , IFNULL( todatesum, 0 ) , IFNULL( compdatecount, 0 ) , IFNULL( compdatesum, 0 ) FROM count_1 LEFT JOIN count_2 ON count_1.compmonth = count_2.compmonth UNION SELECT count2.compmonth, IFNULL( todatecount, 0 ) , IFNULL( todatesum, 0 ) , IFNULL( compdatecount, 0 ) , IFNULL( compdatesum, 0 ) FROM count_1 RIGHT JOIN count_2 ON count_1.compmonth = count_2.compmonth </code></pre> <p>You can format the 0's as per your wish. Also, if your database platform supports the "FULL OUTER JOIN", you can use that instead of making a union of left and right joins.</p> <p>You will have to replace "FROM count_1" with:<br> <code>FROM (select accountID,COUNT(planters.todate) as count2date, SUM(planters.todate) as sum2date ----- -----) count_1</code></p> <p>Similarly for <code>FROM count_2</code>. I know this looks like a huge query, but all this does is joins the 2 tables on common dates, and all the other fields that don't match are specified NULL.</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. This table or related slice is empty.
    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