<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sql case in where clause - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/sql-case-in-where-clause/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/sql-case-in-where-clause/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Thu, 09 Sep 2021 09:32:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>sql case in where clause - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/sql-case-in-where-clause/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What is the difference between a HAVING CLAUSE and a WHERE CLAUSE ?</title>
		<link>https://www.wikitechy.com/interview-questions/sql/what-is-the-difference-between-a-having-clause-and-a-where-clause/</link>
					<comments>https://www.wikitechy.com/interview-questions/sql/what-is-the-difference-between-a-having-clause-and-a-where-clause/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Sun, 18 Jul 2021 20:21:49 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[Allstate Solut interview questions and answers]]></category>
		<category><![CDATA[Capgemini interview questions and answers]]></category>
		<category><![CDATA[case in where clause]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[CGI Group Inc interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[clause]]></category>
		<category><![CDATA[clause examples]]></category>
		<category><![CDATA[Collabera Technologies interview questions and answers]]></category>
		<category><![CDATA[conditional clauses]]></category>
		<category><![CDATA[Conduent interview questions and answers]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[difference between groupby and orderby in sql]]></category>
		<category><![CDATA[difference between having and group by]]></category>
		<category><![CDATA[difference between where and having clause]]></category>
		<category><![CDATA[difference between where and having clause in oracle]]></category>
		<category><![CDATA[difference between where and having clause in sql server]]></category>
		<category><![CDATA[difference between where and having clause in tabular form]]></category>
		<category><![CDATA[FIS Global Business Solutions India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[group by clause]]></category>
		<category><![CDATA[group by clause in sql]]></category>
		<category><![CDATA[group by sql]]></category>
		<category><![CDATA[having clause]]></category>
		<category><![CDATA[having clause in sql]]></category>
		<category><![CDATA[having clause in sql stackoverflow]]></category>
		<category><![CDATA[having vs where performance]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[L&T Infotech interview questions and answers]]></category>
		<category><![CDATA[main difference between having and wheremy]]></category>
		<category><![CDATA[Mindtree interview questions and answers]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[mysql in clause]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[oracle with clause]]></category>
		<category><![CDATA[order by clause]]></category>
		<category><![CDATA[order by clause in sql]]></category>
		<category><![CDATA[Persistent Systems interview questions and answers]]></category>
		<category><![CDATA[Prokarma Softech Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[R Systems interview questions and answers]]></category>
		<category><![CDATA[SAP Labs India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[sql case in where clause]]></category>
		<category><![CDATA[sql having count]]></category>
		<category><![CDATA[sql having vs where]]></category>
		<category><![CDATA[sql join]]></category>
		<category><![CDATA[sql where clause]]></category>
		<category><![CDATA[sql with clause]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[Tata Consultancy Service interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[ValueLabs interview questions and answers]]></category>
		<category><![CDATA[Virtusa Consulting Services Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Wells Fargo interview questions and answers]]></category>
		<category><![CDATA[what is a clause]]></category>
		<category><![CDATA[where clause]]></category>
		<category><![CDATA[where clause in sql]]></category>
		<category><![CDATA[Xoriant Solutions Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[yardi software interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=966</guid>

					<description><![CDATA[Answer : The HAVING clause sets conditions on the GROUP BY...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="" class="color-pink" style="text-align: justify;"></h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<table class="table-bordered table-striped table table-responsive">
<tbody>
<tr>
<th>Where Clause</th>
<th>Having Clause</th>
</tr>
<tr>
<td class="text-leftalign">WHERE clause can be used with &#8211; Select, Insert, and<br />
Update statements.</td>
<td class="text-leftalign">HAVING clause can only be used with the Select statement.</td>
</tr>
<tr>
<td class="text-leftalign">The WHERE search condition is applied before the<br />
grouping operation occurs.</td>
<td class="text-leftalign">The HAVING search condition is applied after the grouping operation occurs.</td>
</tr>
<tr>
<td class="text-leftalign">Aggregate functions cannot be used in the WHERE clause,<br />
unless it is in a sub query contained in a HAVING clause.</td>
<td class="text-leftalign">Aggregate functions can be used in Having clause.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="example-of-where-and-having-clause" class="color-green">Example of WHERE and HAVING clause</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>We have two tables Wikitechy_Employee and Department. Wikitechy_Employee contains details of employees e.g. id, name, age, salary and department id, while Department contains id and department name.</li>
<li>In order to show, which employee works for which department we need to join two tables on DEPT_ID to get the the department name.</li>
<li>Our requirement is to find how many employees are working in each department and average salary of department.</li>
<li>In order to use WHERE clause, we will only include employees who are earning more than 5000.</li>
<li>Before executing our query which contains WHERE, HAVING, and GROUP BY clause, let see data from Wikitechy_Employee and Department table:</li>
</ul>
</div>
</div>
<div class="text-center row" style="text-align: justify;"></div>
<div class="subheading" style="text-align: justify;">
<h2 id="select-from-wikitechy_employee">SELECT * FROM Wikitechy_Employee;</h2>
<table class="table-bordered table-striped table table-responsive">
<tbody>
<tr>
<th>EMP_ID</th>
<th>EMP_NAME</th>
<th>EMP_AGE</th>
<th>EMP_SALARY</th>
<th>DEPT_ID</th>
</tr>
<tr>
<td class="text-leftalign">1</td>
<td class="text-leftalign">George Orwell</td>
<td class="text-leftalign">23</td>
<td class="text-leftalign">10000</td>
<td class="text-leftalign">1</td>
</tr>
<tr>
<td class="text-leftalign">2</td>
<td class="text-leftalign">J.K. Rowling</td>
<td class="text-leftalign">24</td>
<td class="text-leftalign">7000</td>
<td class="text-leftalign">2</td>
</tr>
<tr>
<td class="text-leftalign">3</td>
<td class="text-leftalign">Kurt Vonnegut</td>
<td class="text-leftalign">25</td>
<td class="text-leftalign">8000</td>
<td class="text-leftalign">3</td>
</tr>
<tr>
<td class="text-leftalign">4</td>
<td class="text-leftalign">Virginia Woolf</td>
<td class="text-leftalign">27</td>
<td class="text-leftalign">6000</td>
<td class="text-leftalign">1</td>
</tr>
<tr>
<td class="text-leftalign">5</td>
<td class="text-leftalign">Ernest Hemingway</td>
<td class="text-leftalign">28</td>
<td class="text-leftalign">5000</td>
<td class="text-leftalign">2</td>
</tr>
</tbody>
</table>
</div>
<div class="subheading" style="text-align: justify;">
<h2 id="select-from-department">SELECT * FROM Department;</h2>
<table class="table-bordered table-striped table table-responsive">
<tbody>
<tr>
<th>DEPT_ID</th>
<th>DEPT_NAME</th>
</tr>
<tr>
<td class="text-leftalign">1</td>
<td class="text-leftalign">Accounting</td>
</tr>
<tr>
<td class="text-leftalign">2</td>
<td class="text-leftalign">Marketing</td>
</tr>
<tr>
<td class="text-leftalign">3</td>
<td class="text-leftalign">Sales</td>
</tr>
</tbody>
</table>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="sample-code" class="color-green">Sample Code</h2>
</div>
</div>
<div class="CodeContent" style="text-align: justify;">
<div class="hddn">
<figure class="highlight"><div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-sql code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-sql code-embed-code">SELECT d.DEPT_NAME,<br/>count(e.EMP_NAME) as NUM_EMPLOYEE, <br/>avg(e.EMP_SALARY) as AVG_SALARY FROM Employee e,<br/>Department d WHERE e.DEPT_ID=d.DEPT_ID AND EMP_SALARY &gt; 5000 GROUP BY d.DEPT_NAME;</code></pre> </div></figure>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-green">Output</h2>
</div>
</div>
<table class="table-bordered table-striped table table-responsive">
<tbody>
<tr>
<th>DEPT_NAME</th>
<th>NUM_EMPLOYEE AVG_SALARY</th>
<th>AVG_SALARY</th>
</tr>
<tr>
<td class="text-leftalign">Accounting</td>
<td class="text-leftalign">1</td>
<td class="text-leftalign">8000</td>
</tr>
<tr>
<td class="text-leftalign">Marketing</td>
<td class="text-leftalign">1</td>
<td class="text-leftalign">7000</td>
</tr>
<tr>
<td class="text-leftalign">Sales</td>
<td class="text-leftalign">2</td>
<td class="text-leftalign">8000</td>
</tr>
</tbody>
</table>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>From the number of employee (NUM_EMPLOYEE) column you can see that only Vijay who work for Marketing department is not included in result set because his earning 5000.</li>
<li>This example shows that, condition in WHERE clause is used to filter rows before you aggregate them and then HAVING clause comes in picture for final filtering, which is clear from following query, now Marketing department is excluded because it doesn&#8217;t pass condition in HAVING clause i..e AVG_SALARY &gt; 7000</li>
</ul>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="sample-code-2" class="color-green">Sample Code</h2>
</div>
</div>
<div class="CodeContent" style="text-align: justify;">
<div class="hddn">
<figure class="highlight"><div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-sql code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-sql code-embed-code">SELECT d.DEPT_NAME,<br/>count(e.EMP_NAME) as NUM_EMPLOYEE,<br/>avg(e.EMP_SALARY) as AVG_SALARY FROM Employee e,<br/>Department d WHERE e.DEPT_ID=d.DEPT_ID AND EMP_SALARY &gt; 5000 GROUP BY d.DEPT_NAMEHAVING AVG_SALARY &gt; 7000;</code></pre> </div></figure>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output-2" class="color-green">Output</h2>
</div>
</div>
<table class="table-bordered table-striped table table-responsive">
<tbody>
<tr>
<th>DEPT_NAME</th>
<th>NUM_EMPLOYEE</th>
<th>AVG_SALARY</th>
</tr>
<tr>
<td class="text-leftalign">Accounting</td>
<td class="text-leftalign">1</td>
<td class="text-leftalign">8000</td>
</tr>
<tr>
<td class="text-leftalign">Sales</td>
<td class="text-leftalign">2</td>
<td class="text-leftalign">8000</td>
</tr>
</tbody>
</table>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/sql/what-is-the-difference-between-a-having-clause-and-a-where-clause/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
