p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server ASP (http://p2p.wrox.com/forumdisplay.php?f=101)
-   -   HAVING clause (http://p2p.wrox.com/showthread.php?t=9242)

Adam H-W February 11th, 2004 11:10 AM

HAVING clause
I'm getting an error with this statement

select email from competition where Answer =
'Ripple' and email having count(*)> '1' group by email

The error is:

Incorrect syntax near the keyword 'having'.

Also, the email column is not of an int type so I don't know if > 1 will work with it. Basically, I'm trying to find out if there are more than 1 duplicate email entry.



Jeff Mason February 11th, 2004 12:40 PM

The HAVING clause is a separate clause in the SELECT statement, similar to the WHERE clause. It works just like the WHERE clause, but it selects (grouped) rows after the GROUPing operation. The WHERE clause selects rows before GROUPing is done. Since COUNT is an aggregate function, you must use a GROUP by clause to arrange for rows to be grouped by the value of the 'email' column:

SELECT email FROM competition
WHERE Answer='Ripple'
GROUP BY email

Jeff Mason
Custom Apps, Inc.

Adam H-W February 11th, 2004 01:37 PM

Right, I got you - thanks alot Jeff

All times are GMT -4. The time now is 05:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.