answersLogoWhite

0


Best Answer

The short answer is that the WHERE clause is used for comparing values in the base table, whereas the HAVING clause can be used for filtering the results of aggregate functions in the result set of the query. SELECT * FROM tablename WHERE ID > 100 ...is an example of a WHERE clause. Here's a simple example of a HAVING clause that returns the count of workers with the same last names... SELECT WorkerLastName, COUNT(WorkerLastName) AS WorkerCount FROM tblWorker GROUP BY WorkerLastName HAVING COUNT(WorkerLastName) > 1 The HAVING clause allows you to filter the results of aggregate functions, such as COUNT() or AVG() or SUM(), or MAX() or MIN(), just to name a few. HAVING provides you a means to filter these results in the same query, as opposed to saving the results of a WHERE clause SQL statement to a temporary table and running another query on the temporary table results to extract the same results. To do the HAVING SQL above without the HAVING clause would require the following SQL: SELECT WorkerLastName, COUNT(WorkerLastName) AS WorkerCount INTO TempTable FROM tblWorker GROUP BY WorkerLastName SELECT * FROM TempTable WHERE WorkerCount > 1 DROP TABLE TempTable

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between the where and having sql clauses?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between a statement and a clause in SQL?

An SQL statement is a complete set of clauses which returns a value and ends with a semicolon(;) A statement is made up of several clauses Ex: select * from person where f_name='me'; In this ex ' select * from person where f_name='me';' is the statement and select*, from person, where f_name= are the clauses


What is the difference between T-sql and sql?

T-SQL is Microsoft's version of the generic SQL langauge to be used with, for example, Microsoft SQL Server.


What is the difference between hql and sql?

one of the difference is HQL does not support distinct but SQL supports the distinct in the query


What enables us to view data from a table based on a specific criterion?

Filtering is used to view data from a table based on a specific criterion. This allows users to selectively display only the data that meets certain conditions, making it easier to analyze and work with the information in the table.


Difference between sql and sql plus?

SQL*PLUS is a interface between user and Oracle database. It Provide an environment to use the SQL which is a query language to communicate with oracle database


Difference between sql server 2003 sql server 2005?

There is no such thing as SQL Server 2003. Microft released SQL Server 2005 as the next version of SQL Server 2000.


What is the difference between quel SQL and qbe?

gand maro...is the answer


Difference between SQL Exception class and SQL Warning class?

sql exception which provides information on database access errors where as sql warning provides inforamation on database access warnings.


What are the differences between Pervasive SQL and MS SQL?

Pervasive SQL is a relational database management system designed for embedded applications, while MS SQL, or Microsoft SQL Server, is a full-fledged RDBMS with advanced features for enterprise applications. MS SQL provides more robust scalability, security, and integration options compared to Pervasive SQL. Additionally, MS SQL is commonly used in larger organizations, while Pervasive SQL is often utilized in smaller businesses and embedded systems.


Difference between oracle 10g and sql in points?

god only knows


Which date function is used to find the difference between two dates in SQL?

datediff


Difference between Object-based Data Model and Record-based Data Model?

Object-based data model represents data as objects with attributes and methods, providing a way to model real-world entities in a programming language like Java. On the other hand, record-based data model organizes data into fixed-format records or tuples, typically used in databases like SQL to store and retrieve structured information. Object-based data model offers a more dynamic and flexible way to represent data compared to the rigid structure of record-based models.