Subject: HAVING clause
Posted By: Adam H-W Post Date: 2/11/2004 10:10:32 AM
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.

Thanks

Adam
Reply By: Jeff Mason Reply Date: 2/11/2004 11:40:42 AM
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
HAVING COUNT(*)>1;


Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Reply By: Adam H-W Reply Date: 2/11/2004 12:37:26 PM
Right, I got you - thanks alot Jeff

Go to topic 9196

Return to index page 951
Return to index page 950
Return to index page 949
Return to index page 948
Return to index page 947
Return to index page 946
Return to index page 945
Return to index page 944
Return to index page 943
Return to index page 942