title: MySQL: Query UNION, JOIN with conditional WHERE
body: <p>Say we have the following tables, employee and payroll_slip:</p>
  
  <p>Table: employee</p>
  
  <pre><code> id_employee | name_employee |
      ============|===============|
      1           | john          |
      2           | doe           |
      3           | alex          |
  </code></pre>
  
  <p>Table: payroll_slip</p>
  
  <pre><code>id_slip | id_employee | month_slip | year_slip |
  ========|=============|============|===========|
  1       | 1           | 01         | 2016      |
  2       | 2           | 01         | 2016      |
  3       | 1           | 02         | 2016      |
  4       | 2           | 02         | 2016      |
  5       | 1           | 03         | 2016      |
  6       | 3           | 03         | 2016      |
  </code></pre>
  
  <p>And we want to get the following result where <code>month_slip = '03'</code> AND <code>year_slip = '2016'</code></p>
  
  <pre><code>id_employee | month_slip | year_slip | status_slip
  ============|============|===========|============
  1           | 03         | 2016      | paid
  2           | 03         | 2016      | unpaid
  3           | 03         | 2016      | paid
  </code></pre>
  
  <p>I tried this query:</p>
  
  <pre><code>SELECT 
  a.id_employee, 
  payroll_slip.month_slip, 
  payroll_slip.year_slip, 
  IF(a.id_employee=payroll_slip.id_employee, 'paid', 'unpaid') AS status_slip
      FROM    (
                  SELECT id_employee FROM employee
                  UNION 
                  SELECT id_employee FROM payroll_slip
              ) a
      LEFT OUTER JOIN payroll_slip ON a.id_employee = payroll_slip.id_employee
      LEFT OUTER JOIN employee ON a.id_employee = employee.id_employee
      WHERE payroll_slip.month_slip = '03' AND payroll_slip.year_slip = '2016'
  </code></pre>
  
  <p>Any suggestion for this?</p>