Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would propose to use 2 joins</p> <pre><code>SELECT * FROM photo JOIN photo_selectedTags as photo_selectedTags6 -- this join restricts to 'photo.COUNTER' whic have TAGS_COUNTER = 6 ON photo.COUNTER = photo_selectedTags6.PHOTO_COUNTER AND photo_selectedTags6.TAGS_COUNTER = 6 JOIN photo_selectedTags as photo_selectedTags192 -- this join restricts to 'photo.COUNTER' whic have TAGS_COUNTER = 192 ON photo.COUNTER = photo_selectedTags192.PHOTO_COUNTER AND photo_selectedTags192.TAGS_COUNTER = 192 </code></pre> <p><br/><br/> Also would be possible to achive it with analytical functions (if supported by your DB)</p> <pre><code>-- This one works on teradata. Something similar should work on oracle. Don't know about others SELECT * FROM photo LEFT JOIN photo_selectedTags ON photo.COUNTER = photo_selectedTags.PHOTO_COUNTER QUALIFY max(case when photo_selectedTags.TAGS_COUNTER = 6 then 1 end) over (partition by photo.COUNTER) = 1 AND max(case when photo_selectedTags.TAGS_COUNTER = 192 then 1 end) over (partition by photo.COUNTER) = 1 </code></pre> <p>If you have many values in the list (in addition to 192,6), then this might be possible solution</p> <pre><code>SELECT * FROM photo JOIN ( SELECT PHOTO_COUNTER, count(distinct TAGS_COUNTER) cnt FROM photo_selectedTags WHERE TAGS_COUNTER in (192,6) HAVING cnt = 2 -- adjust this according to the number of different values ) as pht ON photo.COUNTER = pht.PHOTO_COUNTER </code></pre> <p>In subquery only PHOTO_COUNTERs are left which have both (192 and 6), then this is joined</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