Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL LEFT JOIN not working properly
    primarykey
    data
    text
    <p>I'm having trouble getting the result out of my query. I want to fetch the sum and total count of an unit sale in transactions, where the transaction is in a specific zip.</p> <p>Here are my tables: </p> <pre><code>TABLE unit_type( id (Primary key) unit_name (varchar) department_id (Foreign key) ) TABLE transaction( id (PK) commission_fix_out (int) transaction_end_week (int) property_id (FK) unit_type_id (FK) ... ) TABLE property( id (PK) property_zip_id (FK) ... ) </code></pre> <p>My <strong>unit_types</strong> table has the following records:</p> <pre><code>+-----+----------------------+----------------+ | id | unit_name | department_id | +-----+----------------------+----------------+ | 1 | WV construction | 1 | | 2 | WV resale | 1 | | 3 | WV rent | 1 | | 4 | BV industrial sale | 2 | | 5 | BV industrial rent | 2 | | ... | ... | ... | +-----+----------------------+----------------+ </code></pre> <p>Here's how my query looks like:</p> <pre><code>SELECT SUM(commission_fix_out), COUNT(commission_fix_out), unit_name, ut.id FROM unit_type as ut LEFT JOIN transaction as t ON ut.id = t.unit_type_id RIGHT JOIN property as p ON (p.id = t.property_id AND p.property_zip_id = 1459) WHERE ut.department_id = 1 GROUP BY unit_name ORDER BY ut.id </code></pre> <p>which results in:</p> <pre><code>+------------+-------------+-------------+---------+ | SUM(...) | COUNT(..) | unit_name | ut.id | +------------+-------------+-------------+---------+ | 40014 | 11 | WV resale | 2 | | NULL | 0 | WV rent | 3 | +------------+-------------+-------------+---------+ </code></pre> <p>I was expecting another row with <strong>WV construction</strong>, but it doesn't show up. Anyone who knows where i am wrong with this one?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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