Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my take using traditional join syntax:</p> <pre><code>SELECT rocks.name, rocks.latitude, rocks.longitude, rocks.indoor, rocks.address, rocks.phone, rocks.email, rocks.website, rocks.closed, rock_types.type FROM rocks, rock_types WHERE rocks.latitude &gt; -180 AND rocks.latitude &lt; 180 AND rocks.longitude &gt; -180 AND rocks.longitude &lt; 180 AND rocks.type_id = rocks_types.id AND rock_types.type IN ('DWS', 'Top rope') </code></pre> <p>The <code>rocks.id = rocks_types.id</code> does the link between both tables.</p> <p>Here is how you can write the same query using <code>INNER JOIN</code> (both leads to the same result)</p> <pre><code>SELECT rocks.name, rocks.latitude, rocks.longitude, rocks.indoor, rocks.address, rocks.phone, rocks.email, rocks.website, rocks.closed, rock_types.type FROM rocks INNER JOIN rocks_types ON rocks.type_id = rocks_types.id WHERE rocks.latitude &gt; -180 AND rocks.latitude &lt; 180 AND rocks.longitude &gt; -180 AND rocks.longitude &lt; 180 AND rock_types.type IN ('DWS', 'Top rope') </code></pre> <p><strong>EDIT</strong>: Based on your comment, the following will give you a comma separated list of types:</p> <pre><code>SELECT rocks.name, rocks.latitude, rocks.longitude, rocks.indoor, rocks.address, rocks.phone, rocks.email, rocks.website, rocks.closed, (SELECT GROUP_CONCAT(DISTINCT rock_types.type SEPARATOR ',') FROM rock_types WHERE rock_types.id = rocks.id AND rock_types.type IN ('DWS', 'Top rope') GROUP BY rock_types.id ) AS type FROM rocks WHERE rocks.latitude &gt; -180 AND rocks.latitude &lt; 180 AND rocks.longitude &gt; -180 AND rocks.longitude &lt; 180 </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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