{"id":86,"date":"2021-03-19T14:35:47","date_gmt":"2021-03-19T14:35:47","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/?page_id=86"},"modified":"2024-11-20T11:08:41","modified_gmt":"2024-11-20T11:08:41","slug":"conditions","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/reference\/conditions\/","title":{"rendered":"Conditions"},"content":{"rendered":"<h1>Simple Conditions<\/h1>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n\r\n-- equals, is the same as\r\nWHERE quantity = 15                  # number\r\nWHERE surname = &#039;Smith&#039;              # text\r\nWHERE date_of_birth = &#039;2004-11-23&#039;   # date\r\nWHERE appointment = &#039;09:45&#039;          # time\r\nWHERE bill_paid = 1                  # Boolean\r\n\r\n-- is not equal to, is not the same as\r\nWHERE quantity != 15\r\n\r\n-- is less than\r\nWHERE quantity &lt; 15\r\n\r\n-- is less than or equal to\r\nWHERE quantity &lt;= 15\r\n\r\n-- is greater than\r\nWHERE quantity &gt; 15\r\n\r\n-- is greater than or equal to\r\nWHERE quantity &gt;= 15\r\n\r\n\r\n<\/pre>\n<h1>Complex Conditions<\/h1>\n<p>Each condition must be in full. You cannot write:<\/p>\n<pre><span style=\"color: #ff0000\">WHERE forename = 'John' OR 'Jon'\r\n<\/span><\/pre>\n<h2>AND, OR, NOT<\/h2>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n-- and - all conditions must be met\r\nWHERE surname =&#039;MacDonald&#039; \r\n    AND forename = &#039;John&#039;\r\n\r\n-- or - any of the conditions must be met\r\nWHERE quantity = 10 \r\n    OR quantity = 20\r\n\r\n-- not - the condition must not be met\r\nWHERE not (surname = &quot;MacDonald&quot;)\r\n\r\n<\/pre>\n<p>Examples:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n\r\n-- is between two numbers (inclusive)\r\nWHERE quantity&gt;=10 AND quantity &lt;=15\r\n\r\n-- is not between two numbers (inclusive) \r\nWHERE quantity &lt; 10 OR quantity &gt; 15 \r\n \r\n-- is in a list of values\r\nWHERE colour=&#039;black&#039; OR colour=&#039;gold&#039; OR colour=&#039;silver&#039; OR colour=&#039;white&#039;\r\n<\/pre>\n<h2>Advanced Higher Operators<\/h2>\n<p>AH students should use BETWEEN and IN operators as required.<br \/>\nNational 5 and Higher should use complex conditions as above to meet course requirements.<\/p>\n<pre class=\"brush: sql; highlight: [3]; title: ; notranslate\" title=\"\">\r\nWHERE quantity BETWEEN 10 AND 15\r\nWHERE colour IN &#x5B;&#039;black&#039;, &#039;gold&#039;, &#039;silver&#039;, &#039;white&#039;]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Simple Conditions &#8212; equals, is the same as WHERE quantity = 15 # number WHERE surname = &#039;Smith&#039; # text WHERE date_of_birth = &#039;2004-11-23&#039; # date WHERE appointment = &#039;09:45&#039; # time WHERE bill_paid = 1 # Boolean &#8212; is not equal to, is not the same as WHERE quantity != 15 &#8212; is less than WHERE quantity &lt; 15 &#8212; is less than or equal to WHERE quantity &lt;=<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/reference\/conditions\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":53,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-86","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/comments?post=86"}],"version-history":[{"count":15,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/86\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/86\/revisions\/672"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/pages\/53"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputingsql\/wp-json\/wp\/v2\/media?parent=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}