Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 11th, 2004, 11:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default 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.

Thanks

Adam
  #2 (permalink)  
Old February 11th, 2004, 12:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

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:
Code:
SELECT email FROM competition
   WHERE Answer='Ripple'
GROUP BY email
HAVING COUNT(*)>1;
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
  #3 (permalink)  
Old February 11th, 2004, 01:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Right, I got you - thanks alot Jeff


Similar Threads
Thread Thread Starter Forum Replies Last Post
Case in Where Clause acko SQL Server 2000 12 September 12th, 2011 01:43 PM
date between clause mateenmohd Access 2 January 7th, 2008 09:28 AM
SQL Where Clause sudarshan73 Crystal Reports 2 January 11th, 2006 10:01 AM
Order by clause mateenmohd SQL Server 2000 4 April 6th, 2004 06:48 AM
More than 1 WHERE clause? onlyu2 MySQL 1 March 26th, 2004 01:48 PM





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