Note that there are some explanatory texts on larger screens.

plurals
  1. POIgnore WHERE condition if record not found
    primarykey
    data
    text
    <p>I have written the following script: </p> <pre><code>SELECT vil.account_id , vil.imp_id, vil.owner , vil.start_date, CASE WHEN ac.status = 4 THEN status_date ELSE NULL END AS Live_date, cs.country_code FROM ACCOUNT ac INNER JOIN vu_imp_list vil ON vil.account_id = ac.account_id INNER JOIN entity e ON ac.entity_id = e.entity_id INNER JOIN country_specifics cs ON e.country_id = cs.country_id WHERE ac.account_id IN ('000206789', '000207464', '000207696', '000207746') AND (vil.start_date = (SELECT MIN(vils.start_date) FROM vu_imp_list vils WHERE vil.account_id = vils.account_id) </code></pre> <p>This will return the oldest <code>imp_id</code> for each <code>account_id</code>. However, it will ignore those which do not have <code>imp_id</code>. As some <code>account_ids</code> do not have <code>imp_id</code> at the table <code>vu_imp_list</code>; <code>WHERE's second condition</code> will only extract only those records that have correspondent <code>start_date</code> and <code>imp_id</code>. In short, How to ignore this condition in case no corresponding record found in table <code>vu_imp_list</code>. I have found <a href="https://stackoverflow.com/questions/5540416/how-to-ignore-a-condition-in-where-clause">this post</a> for MySQL related but seem something wrong with it as I keep getting error <code>missing SELECT keyword</code></p> <pre><code>SELECT vil.account_id , vil.imp_id, vil.owner , vil.start_date, CASE WHEN ac.status = 4 THEN status_date ELSE NULL END AS Live_date, cs.country_code FROM ACCOUNT ac INNER JOIN vu_imp_list vil ON vil.account_id = ac.account_id INNER JOIN entity e ON ac.entity_id = e.entity_id INNER JOIN country_specifics cs ON e.country_id = cs.country_id WHERE ac.account_id IN ('000206789', '000207464', '000207696', '000207746') AND ((vil.start_date = (SELECT MIN(vils.start_date) FROM vu_imp_list vils WHERE vil.account_id = vils.account_id)) OR NOT EXISTS (vil.start_date = (SELECT MIN(vils.start_date) FROM obi.vu_implementation_list vils WHERE vil.ob10_account_id = vils.ob10_account_id) </code></pre>
    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.
 

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