title: Joining conditionally based on values in 2 different columns in current table
body: <pre><code>SELECT  
      l.*,
      qqs.*,
      qq.*,
      --  cqqs.id As Cosigner_Quote_Set_ID,
      --  borrower_cosigner_quote_set_uuid as Cosigner_Quote_Set_UUID,
      --  cqq.id As Cosigner_Quote_ID,
      --  cqq.uuid As Cosigner_Quote_UUID,
      --  cqq.accept_federal_loan As Cosigner_Quote_Loan_Type,
      --  cqq.program_id As Cosigner_Quote_Program_ID,
      --  cqq.lender_name As Cosigner_Quote_Lender_Name,
      --  cqq.term_in_months As Cosigner_Loan_Term,
      --  cqq.apr As Cosigner_Loan_APR,
      --  cqq.monthly_payment As Cosigner_Loan_Pay,
      IF(tentative_quote_uuid IS NOT NULL,1,0) As Quote_Accepted,
      IF(selected_quote_uuid IS NOT NULL,1,0) As Lender_Accepted,
      loan_key As Loan_Key
  FROM leads_production.leads l
  LEFT JOIN greenhouse_production.citizenship_statuses csb
      ON csb.id = l.citizenship_status_ref
  LEFT JOIN greenhouse_production.citizenship_statuses csc
      ON csc.id = l.cosigner_citizenship_status_ref
  LEFT JOIN core_production.quotes_quote_sets qqs
      ON qqs.uuid = l.quote_set_uuid
  LEFT JOIN core_production.quotes_quotes qq
      ON qq.quote_set_id = qqs.id;
  -- LEFT JOIN core_production.quotes_quote_sets cqqs
  --    ON cqqs.uuid = l.borrower_cosigner_quote_set_uuid
  -- LEFT JOIN core_production.quotes_quotes cqq
  --    ON cqq.quote_set_id = qqs.id;
  </code></pre>
  
  <p>Please look at the commented lines in the above query. I want to write a query wherein the join is either on (qqs and qq tables) OR (cqqs and cqq tables) based on the value in borrower_cosigner_quote_set_uuid.</p>
  
  <p>Something like this:</p>
  
  <pre><code>If borrower_cosigner_quote_set_uuid IS NOT NULL THEN
  -- LEFT JOIN core_production.quotes_quote_sets cqqs
  --  ON cqqs.uuid = l.borrower_cosigner_quote_set_uuid
  -- LEFT JOIN core_production.quotes_quotes cqq
  --  ON cqq.quote_set_id = qqs.id;
  ELSE
      LEFT JOIN core_production.quotes_quote_sets qqs
          ON qqs.uuid = l.quote_set_uuid
      LEFT JOIN core_production.quotes_quotes qq
          ON qq.quote_set_id = qqs.id;`
  </code></pre>
  
  <p>Thanks in advance for your help.</p>