{"id":3910,"date":"2025-06-06T20:07:47","date_gmt":"2025-06-06T20:07:47","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3910"},"modified":"2025-06-07T09:55:40","modified_gmt":"2025-06-07T09:55:40","slug":"sql-and-or-not","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-and-or-not\/","title":{"rendered":"SQL AND \/ OR \/ NOT"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Use <code>AND<\/code>, <code>OR<\/code>, and <code>NOT<\/code> to build <strong>complex filters<\/strong> in your <code>WHERE<\/code> clause.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 How They Work<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>AND<\/strong> \u2014 all conditions must be true<\/li>\n\n\n\n<li><strong>OR<\/strong> \u2014 at least one condition is true<\/li>\n\n\n\n<li><strong>NOT<\/strong> \u2014 reverses the condition (negation)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Examples<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Both conditions must be true\nSELECT * FROM employees \nWHERE department = 'IT' AND salary &gt; 60000;\n\n-- Either condition can be true\nSELECT * FROM employees \nWHERE department = 'HR' OR salary &gt; 70000;\n\n-- Negate a condition\nSELECT * FROM employees \nWHERE NOT department = 'Sales';\n\n-- Combine all\nSELECT * FROM employees \nWHERE (department = 'IT' OR department = 'HR') AND salary &gt; 50000;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Operator<\/th><th>Meaning<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>AND<\/td><td>Both conditions true<\/td><td><code>WHERE dept = 'IT' AND salary &gt; 60000<\/code><\/td><\/tr><tr><td>OR<\/td><td>Either condition true<\/td><td><code>WHERE dept = 'HR' OR salary &gt; 70000<\/code><\/td><\/tr><tr><td>NOT<\/td><td>Negates condition<\/td><td><code>WHERE NOT dept = 'Sales'<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Use these to filter data precisely and flexibly!<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use AND, OR, and NOT to build complex filters in your WHERE clause. \ud83d\udd39 How They Work \ud83d\udd39 Examples \ud83e\udde0 Quick Recap Operator Meaning Example AND Both conditions true WHERE dept = &#8216;IT&#8217; AND salary &gt; 60000 OR Either condition true WHERE dept = &#8216;HR&#8217; OR salary &gt; 70000 NOT Negates condition WHERE NOT dept [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3910","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}