{"id":174149,"date":"2023-11-27T16:49:00","date_gmt":"2023-11-27T15:49:00","guid":{"rendered":"https:\/\/liora.io\/en\/?p=174149"},"modified":"2026-02-06T08:44:42","modified_gmt":"2026-02-06T07:44:42","slug":"sql-where-heres-the-syntax","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/sql-where-heres-the-syntax","title":{"rendered":"SQL WHERE: Here&#8217;s the syntax"},"content":{"rendered":"<p><strong>The WHERE command in SQL is used in queries to filter out data that meets a specific condition. This allows you to extract only the desired rows from a table in a database. With this command, you can select a subset of data according to precise criteria. Find out more about the syntax of the WHERE command in <a href=\"\/formation\/data-ia\/sql\">SQL<\/a>, its use cases and its comparison operators to carry out your queries more efficiently.<\/strong><\/p>\t\t\n\t\t\t<h3>The syntax of the WHERE command in SQL<\/h3>\t\t\n\t\t<p>The WHERE command consists of a SELECT command and the WHERE condition.<\/p><p>The most common syntax is as follows:<\/p><p>SELECT column_name1, column_name2 FROM table_name WHERE a_condition<\/p><p>Let&#8217;s break down this SQL query:<\/p><p>SELECT will select the columns named column_name1 and column_name2<br>FROM will select the table named table_name<br>WHERE adds a condition: select only what respects the condition une_condition.<\/p>\t\t\n\t\t\t<h3>Some examples of WHERE commands<\/h3>\t\t\n\t\t<p>To make the WHERE command more concrete and better understand how it works, let&#8217;s apply it to a specific case. In this example, we&#8217;re using a customer table. It simulates a table containing a company&#8217;s customers and their number of orders.<\/p>\t\t\n\t\t\t\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-9fd4{background-color:#9b9b9b;font-weight:bold;text-align:left;vertical-align:top}\n.tg .tg-0lax{text-align:left;vertical-align:top}\n\n<table>\n<thead>\n  <tr>\n    <th>ID<\/th>\n    <th>First Name<\/th>\n    <th>Last Name<\/th>\n    <th>Email<\/th>\n    <th>Order Count<\/th>\n    <th>City<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>1<\/td>\n    <td>Marie <\/td>\n    <td>Nevier<\/td>\n    <td>mnevier@example.com<\/td>\n    <td>7<\/td>\n    <td>Paris<\/td>\n  <\/tr>\n  <tr>\n    <td>2<\/td>\n    <td>Ga\u00ebtan<\/td>\n    <td>Doucle<\/td>\n    <td>gdoucle@example.com<\/td>\n    <td>4<\/td>\n    <td>Nantes<\/td>\n  <\/tr>\n  <tr>\n    <td>3<\/td>\n    <td>Louis<\/td>\n    <td>Chenard<\/td>\n    <td>lchenard@example.com<\/td>\n    <td>1<\/td>\n    <td>Lyon<\/td>\n  <\/tr>\n  <tr>\n    <td>4<\/td>\n    <td>Olivia<\/td>\n    <td>Caffin<\/td>\n    <td>ocaffin@example.com<\/td>\n    <td>9<\/td>\n    <td>Bordeaux<\/td>\n  <\/tr>\n  <tr>\n    <td>5<\/td>\n    <td>Camille<\/td>\n    <td>Loutran<\/td>\n    <td>cloutran@example.com<\/td>\n    <td>3<\/td>\n    <td>Paris<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\n\t\t\t<h4>Example of selection by city<\/h4>\t\t\n\t\t<p>By using the syntax of the WHERE command and adding the right elements, you can filter this table as you see fit. For example, to select only customers from the city of Paris, we&#8217;d run the query :<\/p><p>SELECT * FROM customers WHERE city = &#8216;Paris&#8217;.<\/p><p>This query returns the following selection:<\/p>\t\t\n\t\t\t\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-pu0z{background-color:#9b9b9b;border-color:inherit;font-weight:bold;text-align:left;vertical-align:top}\n.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}\n\n<table>\n<thead>\n  <tr>\n    <th>ID<\/th>\n    <th>First Name<\/th>\n    <th>Last Name<\/th>\n    <th>Email<\/th>\n    <th>Order Count<\/th>\n    <th>City<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>1<\/td>\n    <td>Marie<\/td>\n    <td>Nevier<\/td>\n    <td>mnevier@example.com<\/td>\n    <td>7<\/td>\n    <td>Paris<\/td>\n  <\/tr>\n  <tr>\n    <td>2<\/td>\n    <td>Camille<\/td>\n    <td>Loutran<\/td>\n    <td>cloutran@example.com<\/td>\n    <td>3<\/td>\n    <td>Paris<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\t\t\n\t\t<p>By using the syntax of the WHERE command and adding the right elements, you can filter this table as you see fit. For example, to select only customers from the city of Paris, we&#8217;d run the query :<\/p><p>SELECT * FROM customers WHERE city = &#8216;Paris&#8217;.<\/p><p>This query returns the following selection:<\/p>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/data-scientist\">Learn how to use SQL<\/a><\/div><\/div>\n\n\t\t\t<h4>Example of selection by number of orders<\/h4>\t\t\n\t\t<p>For a physical or online business, it can be useful to filter customers by number of orders. Let&#8217;s take the initial table and run the following query:<\/p><p>SELECT * FROM customers WHERE nbr_orders &gt;= 4<\/p><p>This query returns all customers who have placed 4 or more orders:<\/p>\t\t\n\t\t\t\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-9fd4{background-color:#9b9b9b;font-weight:bold;text-align:left;vertical-align:top}\n.tg .tg-0lax{text-align:left;vertical-align:top}\n\n<table>\n<thead>\n  <tr>\n    <th>ID<\/th>\n    <th>First Name<\/th>\n    <th>Last Name<\/th>\n    <th>Email<\/th>\n    <th>Order Count<\/th>\n    <th>City<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>1<\/td>\n    <td>Marie<\/td>\n    <td>Nevier<\/td>\n    <td>mnevier@example.com<\/td>\n    <td>7<\/td>\n    <td>Paris<\/td>\n  <\/tr>\n  <tr>\n    <td>2<\/td>\n    <td>Ga\u00ebtan<\/td>\n    <td>Doucle<\/td>\n    <td>gdoucle@example.com<\/td>\n    <td>4<\/td>\n    <td>Nantes<\/td>\n  <\/tr>\n  <tr>\n    <td>3<\/td>\n    <td>Olivia<\/td>\n    <td>Caffin<\/td>\n    <td>ocaffin@example.com<\/td>\n    <td>9<\/td>\n    <td>Bordeaux<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\n\t\t\t<h3>Comparison operators in the WHERE command<\/h3>\t\t\n\t\t<p>In our two examples, we&#8217;ve used the = and &gt;= operators to filter the results in the SQL query. But these are not the only operators that can be used with the WHERE command. See the table below for a list of the most commonly used operators:<\/p>\t\t\n\t\t\t\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-52qd{background-color:#6665cd;font-size:18px;font-weight:bold;text-align:left;vertical-align:top}\n.tg .tg-0lax{text-align:left;vertical-align:top}\n\n<table>\n<thead>\n  <tr>\n    <th>Operator<\/th>\n    <th>Operator Description<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>=<\/td>\n    <td>Equal<\/td>\n  <\/tr>\n  <tr>\n    <td>&lt;&gt; or !=<\/td>\n    <td>Not Equal<\/td>\n  <\/tr>\n  <tr>\n    <td>&lt;<\/td>\n    <td>Less Than<\/td>\n  <\/tr>\n  <tr>\n    <td>&gt;<\/td>\n    <td>Greater Than<\/td>\n  <\/tr>\n  <tr>\n    <td>&lt;=<\/td>\n    <td>Less Than or Equal<\/td>\n  <\/tr>\n  <tr>\n    <td>&gt;=<\/td>\n    <td>Greater Than or Equal<\/td>\n  <\/tr>\n  <tr>\n    <td>IN<\/td>\n    <td>List of Possible Values<\/td>\n  <\/tr>\n  <tr>\n    <td>BETWEEN<\/td>\n    <td>Values within a Data Range (value range or date range)<\/td>\n  <\/tr>\n  <tr>\n    <td>LIKE<\/td>\n    <td>Matches the beginning, middle, or end of a word<\/td>\n  <\/tr>\n  <tr>\n    <td>IS NULL<\/td>\n    <td>Value is Null<\/td>\n  <\/tr>\n  <tr>\n    <td>IS NOT NULL<\/td>\n    <td>Value is Not Null<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\n\t\t\t<h3>Conclusion on SQL WHERE<\/h3>\t\t\n\t\t<p>In short, <strong>WHERE is a particularly useful SQL<\/strong> command for selecting the rows of a table that meet a specific condition. The various operators allow you to use the WHERE command to filter different values, such as numbers, dates or words.<\/p><p>&nbsp;<\/p><p>?Related articles:<\/p><table dir=\"ltr\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" data-sheets-root=\"1\"><colgroup><col width=\"656\"><\/colgroup><tbody><tr><td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;SQL Developer: What is it? What's it for?&quot;}\" data-sheets-hyperlink=\"https:\/\/liora.io\/en\/sql-developer-what-is-it-whats-it-for\"><a href=\"https:\/\/liora.io\/en\/sql-developer-what-is-it-whats-it-for\" target=\"_blank\" rel=\"noopener\">SQL Developer: What is it? What&#8217;s it for?<\/a><\/td><\/tr><tr><td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;SQL Tutorial: Top 5 Most Useful Methods&quot;}\" data-sheets-hyperlink=\"https:\/\/liora.io\/en\/sql-tutorial-top-5-most-useful-methods\"><a href=\"https:\/\/liora.io\/en\/sql-tutorial-top-5-most-useful-methods\" target=\"_blank\" rel=\"noopener\">SQL Tutorial: Top 5 Most Useful Methods<\/a><\/td><\/tr><tr><td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;SQL joins: everything you need to know about table associations&quot;}\" data-sheets-hyperlink=\"https:\/\/liora.io\/en\/sql-joins-everything-you-need-to-know-about\"><a href=\"https:\/\/liora.io\/en\/sql-joins-everything-you-need-to-know-about\" target=\"_blank\" rel=\"noopener\">SQL joins: everything you need to know about table associations<\/a><\/td><\/tr><tr><td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;SQL vs NoSQL: differences, uses, advantages and disadvantages&quot;}\" data-sheets-hyperlink=\"https:\/\/liora.io\/en\/sql-vs-nosql\"><a href=\"https:\/\/liora.io\/en\/sql-vs-nosql\" target=\"_blank\" rel=\"noopener\">SQL vs NoSQL: differences, uses, advantages and disadvantages<\/a><\/td><\/tr><tr><td data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;NoSQL: All about non-relational databases&quot;}\" data-sheets-hyperlink=\"https:\/\/liora.io\/en\/all-about-non-relational-databases\"><a href=\"https:\/\/liora.io\/en\/all-about-non-relational-databases\" target=\"_blank\" rel=\"noopener\">NoSQL: All about non-relational databases<\/a><\/td><\/tr><\/tbody><\/table>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/data-scientist\">Master SQL with Liora<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The WHERE command in SQL is used in queries to filter out data that meets a specific condition. This allows you to extract only the desired rows from a table in a database. With this command, you can select a subset of data according to precise criteria. Find out more about the syntax of the [&hellip;]<\/p>\n","protected":false},"author":76,"featured_media":174150,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2433],"class_list":["post-174149","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/174149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/76"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=174149"}],"version-history":[{"count":1,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/174149\/revisions"}],"predecessor-version":[{"id":206209,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/174149\/revisions\/206209"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/174150"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=174149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=174149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}