Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For returning ALL when only location matches, try following query</p> <p><strong>SQL QUERY</strong></p> <pre><code>select m.item, m.location, (CASE WHEN m.card like t.card THEN m.card ELSE 'All' END) as card from mst_item as m, time_factor as t WHERE m.location like t.location </code></pre> <p><strong>ORACLE QUERY</strong></p> <pre><code>select mst_item.item, mst_item.location, (CASE WHEN mst_item.card = time_factor.card THEN mst_item.card ELSE 'All' END) as card from mst_item, time_factor WHERE mst_item.location like time_factor.location; </code></pre> <p><strong>OUTPUT</strong></p> <p><img src="https://i.stack.imgur.com/Owu76.png" alt="enter image description here"></p> <p>A better query can be</p> <p><strong>SQL QUERY</strong></p> <pre><code>select m.item, m.location,t.card from mst_item as m, time_factor as t WHERE m.location like t.location </code></pre> <p><strong>ORACLE QUERY</strong></p> <pre><code>select mst_item.item, mst_item.location, time_factor.card from mst_item, time_factor WHERE mst_item.location like time_factor.location; </code></pre> <p><strong>OUTPUT</strong></p> <p><img src="https://i.stack.imgur.com/4696J.png" alt="enter image description here"></p> <p>One other variation can be </p> <pre><code>select m.item, m.location, (CASE WHEN m.card like t.card THEN m.card WHEN t.card like 'ALL' THEN t.card END) as mcard from mst_item as m, time_factor as t WHERE m.location like t.location AND (CASE WHEN m.card like t.card THEN m.card WHEN t.card like 'ALL' THEN t.card END) != ''; </code></pre> <p>ONE more variant can be </p> <p><strong>SQL QUERY</strong></p> <pre><code>select m.item, m.location, (CASE WHEN m.card like t.card THEN m.card WHEN t.card like 'ALL' THEN t.card END) as mcard from mst_item as m, time_factor as t WHERE m.location like t.location AND (CASE WHEN m.card like t.card THEN m.card WHEN t.card like 'ALL' THEN t.card END) != ''; </code></pre> <p><strong>ORACLE QUERY</strong> </p> <pre><code>select mst_item.item, mst_item.location, (CASE WHEN mst_item.card = time_factor.card THEN mst_item.card WHEN time_factor.card like 'ALL' THEN time_factor.card END) as card from mst_item, time_factor WHERE mst_item.location like time_factor.location AND (CASE WHEN mst_item.card = time_factor.card THEN mst_item.card WHEN time_factor.card like 'ALL' THEN time_factor.card END) IS NOT NULL ; </code></pre> <p><strong>OUTPUT</strong></p> <p><img src="https://i.stack.imgur.com/HU8t3.png" alt="enter image description here"></p> <p>Please check outputs that you want so we can modify accordingly.</p> <p>SQL fiddle demo at <a href="http://sqlfiddle.com/#!2/53e53/21" rel="nofollow noreferrer">http://sqlfiddle.com/#!2/53e53/21</a></p> <p>Oracle fiddle demo at <a href="http://sqlfiddle.com/#!4/d28b1/26" rel="nofollow noreferrer">http://sqlfiddle.com/#!4/d28b1/26</a></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