{"id":98226,"date":"2020-12-21T11:00:00","date_gmt":"2020-12-21T09:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=98226"},"modified":"2021-11-07T23:47:19","modified_gmt":"2021-11-07T21:47:19","slug":"sql-where-clause-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/","title":{"rendered":"SQL Where Clause Example"},"content":{"rendered":"<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>In this article, we will look at the SQL Where Clause. The Update, Delete, and Select statements have an optional Where clause.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-where-in-relational-algebra\">2. Where in Relational Algebra<\/h2>\n<p>The condition we put to filter records is the \u201cwhere\u201d clause in Relational Algebra. The condition parameter is :<\/p>\n<p>\u03c3 <sub>(Cond)<\/sub>(Relation Name)<\/p>\n<p>Here,<\/p>\n<div class=\"wp-block-group\">\n<div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<ul class=\"wp-block-list\">\n<li> \u03c3= selector<\/li>\n<li>cond = filter condition i.e. where clause in a SQL query.<\/li>\n<li>Relation Name = name of the table.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-3-sql-where-clause\">3. SQL Where Clause<\/h2>\n<p>The \u201cwhere\u201d clause is optional.  Data Manipulation Language constructs like Select, Update, and Delete use it. Although optional it plays a very important role in getting data across multiple tables. <\/p>\n<p>The basic syntax of a where clause is as follows:<\/p>\n<p>Select \/Update\/Delete \u2026 <br \/><em>[WHERE condition1 [AND [OR]] condition2&#8230;..<\/em> <\/p>\n<p>Condition1, condition2, etc are the filter conditions.<\/p>\n<p>Should we miss the where clause in the Update or Delete, the entire table will be updated or deleted. This leads to a lot of data loss.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-4-where-clause-optimization-in-mysql\">4. Where Clause optimization in MySQL<\/h2>\n<p>MySQL engine does optimizations internally to make queries run faster and more efficiently. Incorrect or inefficiently written queries especially on large datasets can cause serious performance problems for both the database as well as the application consuming the data. Hence, optimization of where clause is crucial. &nbsp;Some of the basic optimizations are as follows:<\/p>\n<ul class=\"wp-block-list\" type=\"1\">\n<li>Remove extra parentheses.<\/li>\n<li>&nbsp;Values that can be folded are folded constantly.<\/li>\n<li>Remove redundant constant conditions.<\/li>\n<li>Evaluate constant expressions used by indexes only once.<\/li>\n<li>Remove out-of-range and constant numeric types of values. They are not auto-cast to the higher type anymore.<\/li>\n<li>MySQL can detect invalid statements and stop retrieval to give back no rows.<\/li>\n<li>Merge the Where and Having if there is no GROUP BY.<\/li>\n<li>MySQL also rearranges the statements in the where clause to get faster execution by skipping unnecessary rows.<\/li>\n<\/ul>\n<p>These are just some of the optimizations that MySQL engine does. The complete details of optimization are available <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/where-optimization.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n<p>Users can also perform their own optimizations using the \u201cExplain\u201d statement in MySQL. How to use the \u201cExplain\u201d statement is given <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/explain.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. Using explain plan for Query tuning is in this <a href=\"https:\/\/dev.mysql.com\/doc\/workbench\/en\/wb-tutorial-visual-explain-dbt3.html\" target=\"_blank\" rel=\"noreferrer noopener\">tutorial<\/a>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_explain_plan.jpg\"><img decoding=\"async\" width=\"810\" height=\"650\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_explain_plan.jpg\" alt=\"SQL Where - Sample explain plan in MySQL workbench\" class=\"wp-image-98228\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_explain_plan.jpg 810w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_explain_plan-300x241.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_explain_plan-768x616.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption>Sample explain plan in MySQL workbench<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-4-1-setup-for-examples\">4.1 Setup for examples<\/h3>\n<p>Forgoing through the examples related to the Where clause, we will consider the database called \u201cEmployeesDB\u201d. This is a sample database by MySQL. The structure of the employees is available in this <a href=\"https:\/\/dev.mysql.com\/doc\/employee\/en\/sakila-structure.html\" target=\"_blank\" rel=\"noreferrer noopener\">document<\/a>. For running the queries, we will use the MySQL Workbench. The documentation for MySQL Workbench is available <a href=\"https:\/\/dev.mysql.com\/doc\/workbench\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2 class=\"wp-block-heading\" id=\"h-5-examples-with-where-clause\">5. Examples with Where Clause<\/h2>\n<p>We will see various examples with the where clause. The examples are given for the select clause but the syntax and examples pertaining to the Where clause is applicable to Delete and Update Queries as well. &nbsp;<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-5-1-simple-where-clause-examples\">5.1 Simple Where Clause examples<\/h3>\n<p>We can use the Where Clause with just a hard-coded value and an equals sign. This can return either no or more records.<\/p>\n<p>Single Record Query:<\/p>\n<pre class=\"brush:sql\"> SELECT * FROM DEPARTMENTS WHERE DEPT_NAME = 'MARKETING';<\/pre>\n<p><\/p>\n<p>Multiple records:<\/p>\n<pre class=\"brush:sql\"> SELECT * FROM SALARIES WHERE EMP_NO = 10001;<\/pre>\n<p><\/p>\n<p>No records:<\/p>\n<pre class=\"brush:sql\">SELECT * FROM DEPARTMENTS \nWHERE DEPT_NAME = 'APPLICATION DEVELOPMENT';\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/simple_where.jpg\"><img decoding=\"async\" width=\"810\" height=\"627\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/simple_where.jpg\" alt=\"SQL Where - Simple Queries with = \" class=\"wp-image-98229\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/simple_where.jpg 810w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/simple_where-300x232.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/simple_where-768x594.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption>Simple Queries with = in where clause<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-2-with-operators\">5.2 With Operators: &lt;,&gt;,!=<\/h3>\n<p>We can use operators like &lt;, &lt;=,&gt;,&gt;=, != to filter records. Given below are examples of &lt;,&gt; and !=<\/p>\n<p>Queries:<\/p>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT * FROM SALARIES WHERE SALARY &gt; 155700;<\/pre>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT * FROM SALARIES WHERE SALARY &lt; 39000;<\/pre>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT COUNT(*),TITLE FROM TITLES WHERE TITLE != 'STAFF'\nGROUP BY TITLE;<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_with_operators.jpg\"><img decoding=\"async\" width=\"800\" height=\"621\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_with_operators.jpg\" alt=\"SQL Where - Using  greater than , less than  and not equals operators\" class=\"wp-image-98230\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_with_operators.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_with_operators-300x233.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_with_operators-768x596.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption>Using  greater than , less than  and not equals operators<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-3-where-clauses-with-in-and-not-in\">5.3 Where clauses with IN and NOT IN.<\/h3>\n<p>To check records based on several values we can use the \u201cIN\u201d and \u201cNot IN\u201d operators. Below are simple examples of the same. Subqueries also use these operators.<\/p>\n<pre class=\"brush:sql\">SELECT COUNT(EMP_NO),TITLE FROM TITLES \nWHERE TITLE IN ('SENIOR ENGINEER', 'ENGINEER', 'ASSISTANT ENGINEER')\nGROUP BY TITLE;<\/pre>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT COUNT(EMP_NO),TITLE FROM TITLES \nWHERE TITLE NOT IN ('SENIOR ENGINEER', 'ENGINEER', 'ASSISTANT ENGINEER')\nGROUP BY TITLE;<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_NOT_IN.jpg\"><img decoding=\"async\" width=\"716\" height=\"723\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_NOT_IN.jpg\" alt=\"Using In and Not IN\" class=\"wp-image-98231\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_NOT_IN.jpg 716w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_NOT_IN-297x300.jpg 297w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_NOT_IN-150x150.jpg 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_NOT_IN-70x70.jpg 70w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/a><figcaption>Using In and Not IN<\/figcaption><\/figure>\n<\/div>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT * FROM EMPLOYEES WHERE EMP_NO IN\n(SELECT DISTINCT EMP_NO FROM TITLES WHERE TITLE IN ('Staff','Technique Leader'))\nLIMIT 20;\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_Subquery.jpg\"><img decoding=\"async\" width=\"600\" height=\"471\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_Subquery.jpg\" alt=\"Using IN in a Subquery\" class=\"wp-image-98232\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_Subquery.jpg 600w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IN_Subquery-300x236.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption>Using IN in a Subquery<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-4-where-clauses-with-and-or-and-like\">5.4 Where clauses with AND, OR and LIKE<\/h3>\n<p>The operators AND,OR etc are used to add multiple filters or conditions. LIKE is used when an incomplete pattern needs to be used. AND and OR are extensively used when joining multiple tables. Given below are simple examples of using these operators.<\/p>\n<pre class=\"brush:sql\">SELECT DISTINCT EMP_NO FROM SALARIES \nWHERE SALARY = 39000\nLIMIT 20;<\/pre>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT COUNT(*),DEPT_NO FROM DEPT_EMP \nWHERE DEPT_NO = 'D002' OR DEPT_NO = 'D008' \nGROUP BY DEPT_NO;<\/pre>\n<p><\/p>\n<pre class=\"brush:sql\">SELECT * FROM EMPLOYEES \nWHERE HIRE_DATE LIKE '1999%'\nAND GENDER = 'F'\nLIMIT 20;<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_AND_OR.jpg\"><img decoding=\"async\" width=\"800\" height=\"357\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_AND_OR.jpg\" alt=\"And, Or and Like\" class=\"wp-image-98233\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_AND_OR.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_AND_OR-300x134.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_AND_OR-768x343.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption>And,Or,LIKE <\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-5-where-clause-with-exists-example\">5.5 Where clause with EXISTS example<\/h3>\n<p>Exists is used with a subquery. IF the subquery returns any result(s) then the records from the table in the main query are returned.<\/p>\n<pre class=\"brush:sql\">SELECT * FROM EMPLOYEES WHERE \nEXISTS \n(SELECT 1 \nFROM TITLES2);\n<\/pre>\n<p>Here the Titles2 table has no records and hence the subquery does not return any records. Due to this no records will be returned from the Employees table either.<\/p>\n<pre class=\"brush:sql\">SELECT * FROM EMPLOYEES WHERE \nEXISTS \n(SELECT 1 \nFROM TITLES)\nLIMIT 20;\n<\/pre>\n<p>Here the Titles table has records and hence employees table also returns records.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_exists.jpg\"><img decoding=\"async\" width=\"810\" height=\"524\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_exists.jpg\" alt=\"Exists Clause in Where\" class=\"wp-image-98234\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_exists.jpg 810w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_exists-300x194.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_exists-768x497.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption>Exists Clause in Where<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-6-not-exists-clause\">5.6 Not Exists Clause<\/h3>\n<p>Not Exists works exactly opposite to the Exists Clause as is seen in the below examples<\/p>\n<pre class=\"brush:sql\">SELECT * FROM EMPLOYEES WHERE \nNOT EXISTS \n(SELECT 1 \nFROM TITLES2)\nLIMIT 20;\n<\/pre>\n<p>Here, since the titles2 does not return any records and the \u201cNot Exists\u201d is used, the records from Employees table are returned.<\/p>\n<pre class=\"brush:sql\">SELECT * FROM EMPLOYEES WHERE \nNOT EXISTS \n(SELECT 1 \nFROM TITLES);\n<\/pre>\n<p>Conversely, the above query will not return any records.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_Not_Exists.jpg\"><img decoding=\"async\" width=\"800\" height=\"571\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_Not_Exists.jpg\" alt=\"Not Exists with sql Where\" class=\"wp-image-98235\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_Not_Exists.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_Not_Exists-300x214.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_Not_Exists-768x548.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption>Not Exists with Where<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-7-where-with-is-null\">5.7 Where with IS NULL<\/h3>\n<p>Whenever we use the \u201cIs NULL\u201d for a column, then only the records with Null values for the specified column are returned. This is extremely useful while cleaning up data.<\/p>\n<pre class=\"brush:sql\">SELECT * FROM DEPT_EMP WHERE to_DATE IS NULL;<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IS_NULL.jpg\"><img decoding=\"async\" width=\"596\" height=\"587\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IS_NULL.jpg\" alt=\"IS NULL in sql Where\" class=\"wp-image-98236\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IS_NULL.jpg 596w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IS_NULL-300x295.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_IS_NULL-70x70.jpg 70w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/a><figcaption>IS NULL in Where<\/figcaption><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\" id=\"h-5-8-where-for-multiple-tables\">5.8 Where for multiple tables<\/h3>\n<p>Where clause is used for filtering records from multiple tables. These queries include joins, subqueries, operators, etc, and can be super complex. These are the queries in which optimization comes in handy. Given, below is a fairly simple example of getting data from multiple tables.<\/p>\n<pre class=\"brush:sql\">SELECT E.EMP_NO,E.FIRST_NAME,E.LAST_NAME,E.GENDER,D.DEPT_NAME,T.TITLE,S.SALARY\nFROM EMPLOYEES E, DEPT_EMP DM,DEPARTMENTS D,SALARIES S,TITLES T\nWHERE E.EMP_NO = DM.EMP_NO\nAND DM.DEPT_NO = D.DEPT_NO\nAND E.EMP_NO = S.EMP_NO\nAND E.EMP_NO = T.EMP_NO\nAND DM.TO_DATE = '9999-01-01'\nAND S.TO_DATE = '9999-01-01'\nAND T.TITLE='ENGINEER'\nLIMIT 15;\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_multiple_tables.jpg\"><img decoding=\"async\" width=\"810\" height=\"669\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_multiple_tables.jpg\" alt=\"Joins using sql Where\" class=\"wp-image-98237\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_multiple_tables.jpg 810w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_multiple_tables-300x248.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/where_multiple_tables-768x634.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption>Joins <\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-6-summary\">6. Summary<\/h2>\n<p>In the article, we saw examples of using the Where Clause in MySQL. We also saw how it is optimized and its importance in query building. The Where Clause is an extremely important clause and is used with all the Data Manipulation Language constructs like Select, Update, Delete, etc.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-7-download-the-source-code\">7. Download the Source Code<\/h2>\n<p>This was an example of the SQL Where Clause using MySQL RDBMS.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/12\/sql_where_examples.zip\"><strong> SQL Where Clause Example <\/strong><\/a><\/div>\n<p><strong>Last updated on Nov. 07th, 2021<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this article, we will look at the SQL Where Clause. The Update, Delete, and Select statements have an optional Where clause. 2. Where in Relational Algebra The condition we put to filter records is the \u201cwhere\u201d clause in Relational Algebra. The condition parameter is : \u03c3 (Cond)(Relation Name) Here, \u03c3= selector cond &hellip;<\/p>\n","protected":false},"author":232,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[647],"class_list":["post-98226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-mysql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Where Clause Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"The \u201cwhere\u201d clause is optional. Data Manipulation Language constructs like Select, Update, and Delete use it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Where Clause Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"The \u201cwhere\u201d clause is optional. Data Manipulation Language constructs like Select, Update, and Delete use it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-21T09:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-07T21:47:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Reshma Sathe\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Reshma Sathe\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\"},\"author\":{\"name\":\"Reshma Sathe\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/079aa9a12c7b8ebea3391ebeb6036a74\"},\"headline\":\"SQL Where Clause Example\",\"datePublished\":\"2020-12-21T09:00:00+00:00\",\"dateModified\":\"2021-11-07T21:47:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\"},\"wordCount\":927,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"mysql\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\",\"name\":\"SQL Where Clause Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2020-12-21T09:00:00+00:00\",\"dateModified\":\"2021-11-07T21:47:19+00:00\",\"description\":\"The \u201cwhere\u201d clause is optional. Data Manipulation Language constructs like Select, Update, and Delete use it.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL Where Clause Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/079aa9a12c7b8ebea3391ebeb6036a74\",\"name\":\"Reshma Sathe\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/reshma_sathe-96x96.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/reshma_sathe-96x96.png\",\"caption\":\"Reshma Sathe\"},\"description\":\"I am a recent Master of Computer Science degree graduate from the University Of Illinois at Urbana-Champaign.I have previously worked as a Software Engineer with projects ranging from production support to programming and software engineering.I am currently working on self-driven projects in Java, Python and Angular and also exploring other frontend and backend technologies.\",\"sameAs\":[\"www.linkedin.com\/in\/reshma-sathe\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/reshma-sathe\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Where Clause Example - Java Code Geeks","description":"The \u201cwhere\u201d clause is optional. Data Manipulation Language constructs like Select, Update, and Delete use it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/","og_locale":"en_US","og_type":"article","og_title":"SQL Where Clause Example - Java Code Geeks","og_description":"The \u201cwhere\u201d clause is optional. Data Manipulation Language constructs like Select, Update, and Delete use it.","og_url":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-12-21T09:00:00+00:00","article_modified_time":"2021-11-07T21:47:19+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Reshma Sathe","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Reshma Sathe","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/"},"author":{"name":"Reshma Sathe","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/079aa9a12c7b8ebea3391ebeb6036a74"},"headline":"SQL Where Clause Example","datePublished":"2020-12-21T09:00:00+00:00","dateModified":"2021-11-07T21:47:19+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/"},"wordCount":927,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["mysql"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/","url":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/","name":"SQL Where Clause Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2020-12-21T09:00:00+00:00","dateModified":"2021-11-07T21:47:19+00:00","description":"The \u201cwhere\u201d clause is optional. Data Manipulation Language constructs like Select, Update, and Delete use it.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/sql-where-clause-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL Where Clause Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/079aa9a12c7b8ebea3391ebeb6036a74","name":"Reshma Sathe","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/reshma_sathe-96x96.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/reshma_sathe-96x96.png","caption":"Reshma Sathe"},"description":"I am a recent Master of Computer Science degree graduate from the University Of Illinois at Urbana-Champaign.I have previously worked as a Software Engineer with projects ranging from production support to programming and software engineering.I am currently working on self-driven projects in Java, Python and Angular and also exploring other frontend and backend technologies.","sameAs":["www.linkedin.com\/in\/reshma-sathe"],"url":"https:\/\/examples.javacodegeeks.com\/author\/reshma-sathe\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/98226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/232"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=98226"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/98226\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=98226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=98226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=98226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}