Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The simplest explanation is that you have only a single "year" column in your table. (We may be mistakenly implying (from the references to "year_1" and "year_2" in your question) that your table has two separate "year" columns you are wanting to check.)</p> <p>If you have only one "year" column that you are checking, then it's pretty simple query:</p> <pre><code>SELECT p.* FROM persons p WHERE p.year &gt;= $year_1 AND p.year &lt;= $year_2 </code></pre> <p>But your question seems to reference two separate columns: year_1 and year_2, in addition to your two variables $year_1 and $year_2. </p> <p>So, another possible interpretation of the spec is that the year_1 and year_2 columns are lower and upper bounds of a continuous range, and you want to find rows that satisfy an entire given range of years. </p> <p>As an example, year_1 might be "birth year" and year_2 might be "death year", and I am wanting to find all rows from the persons table who were "alive" EVERY year in a given range:</p> <pre><code>SELECT p.* FROM persons p WHERE p.year_1 &lt;= $year_1 AND p.year_2 &gt;= $year_2 </code></pre> <p>(I don't think this is what you're asking, but I'm not sure.)</p> <p>Another possible interpretation is that I want to find anyone that was "alive" during ANY (but not necessarily all) years in a given range. I'd get that with a query like:</p> <pre><code> SELECT p.* FROM persons p WHERE p.year_1 &lt;= $year_2 OR p.year_2 &gt;= $year_1 </code></pre> <p>Or, I may be asking a fundamentally different question, looking for an event year during particular range of years.</p> <p>Like I want to find anyone that was either "born" or that "died" in a given range of years...</p> <pre><code> SELECT p.* FROM persons p WHERE p.year_1 &gt;= $year_1 AND p.year_1 &lt;= $year_2 OR p.year_2 &gt;= $year_1 AND p.year_2 &lt;= $year_2 </code></pre> <p>But again, it's not clear from your question which (if any) of those result sets you actually want to return.</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.
    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