Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>If Feature_ID = 1 ,2 , the result must <strong>only</strong> get Hotel_ID = 1</p> </blockquote> <p>Because only Hotel_ID = 1 has both features, correct? Assuming <code>#FORM.Feature_ID#</code> does not contain duplicates, use a HAVING clause to dynamically identify hotels with all of the requested features. </p> <pre><code>SELECT Hotel_ID, COUNT(Feature_ID) AS FeatureCount FROM Bridge_Hotel_Feature &lt;!--- find matching features ---&gt; WHERE Feature_ID IN ( &lt;cfqueryparam value="#FORM.Feature_ID#" cfsqltype="cf_sql_integer" list="true"&gt; ) GROUP BY Hotel_ID &lt;!--- having ALL of the requested features ---&gt; HAVING COUNT(Feature_ID) = &lt;cfqueryparam value="#listLen(FORM.Feature_ID)#" cfsqltype="cf_sql_integer"&gt; </code></pre> <p>You could then join to it as a derived table or possibly a subquery. The sql needs optimization, but conceptually something like</p> <pre><code>SELECT h.Hotel_ID, h.Name, f.Feature FROM Hotel h INNER JOIN Bridge_Hotel_Feature b ON b.Hotel_ID = h.Hotel_ID INNER JOIN Features f ON b.Feature_ID = f.Feature_ID INNER JOIN ( SELECT Hotel_ID, COUNT(Feature_ID) AS FeatureCount FROM Bridge_Hotel_Feature &lt;!--- find matching features ---&gt; WHERE Feature_ID IN ( &lt;cfqueryparam value="#FORM.Feature_ID#" cfsqltype="cf_sql_integer" list="true"&gt; ) GROUP BY Hotel_ID &lt;!--- having ALL of the requested features ---&gt; HAVING COUNT(Feature_ID) = &lt;cfqueryparam value="#listLen(FORM.Feature_ID)#" cfsqltype="cf_sql_integer"&gt; ) ck ON ck.Hotel_ID = h.Hotel_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