Stefano, OOh! You're taking me back a few years. As best I remember, the 'HAVING' operator applies to the results returned by the query not in shaping the results to be generated. For example, if you have a table that stores trouble tickets per user. You select the user's last name, first name, and number of tickets they've called in. In your query, you use a 'Having' statement to only see people who've had more than 1-ticket (see example below)
-- Example Query: -- Query returns a list of users that have had more than one -- trouble ticket with a severity greater than 4 (severity is -- 1 through 5). SELECT COUNT(tkt.*), tkt.last_name, tkt.first_name FROM tbl_trouble_tickets AS tkt WHERE tkt.severity > 4 HAVING COUNT(tkt.*) > 1; -- Example Result: 3, Jackson, Janet 2, Jackson, Michael The RDMS is going to first retrieve a record set with count, last name, first name for all users with tickets of severity greater than 4. From THAT recordset the DBMS will display items with a count greater than 1. The point being, 'HAVING' only operates on the recordset retrieved from the prefixing query. Therefore, if a field doesn't exist in the query, you cannot use it in the 'HAVING' statement. Regards, Adam -----Original Message----- From: Stefano Fraccaro [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 03, 2003 9:44 AM To: [EMAIL PROTECTED] Subject: HAVING column not in select_statement I have a query with a column in HAVING clause that not refer any column listed in SELECT statement because I don't need to group by this column and ... this query don't work. It's possible or this feature is planned for the future? Any solution? Thanks -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]