Ranjith93
Ranjith93

Reputation: 33

MySql - unknown column ename in having clause

MariaDB [testingcampus]> select * from employee;

+-----+--------+-----------+--------+
| EID | Ename  | City      | salary |
+-----+--------+-----------+--------+
| 100 | smith  | Bangalore |  10000 |
| 101 | carl   | Bangalore |  12000 |
| 102 | Ram    | Chennai   |  12000 |
| 103 | pankaj | Hyderabad |   5000 |
| 104 | vikram | Pune      |   2000 |
+-----+--------+-----------+--------+
5 rows in set (0.00 sec)

For the above table when I typed the below code I get an error

MariaDB [testingcampus]> Select eid from employee having ename= "Vikram";
ERROR 1054 (42S22): Unknown column 'ename' in 'having clause'

Upvotes: 0

Views: 394

Answers (2)

Robert
Robert

Reputation: 8571

From http://www.mysqltutorial.org/mysql-having.aspx:

The HAVING clause is used in the SELECT statement to specify filter conditions for a group of rows or aggregates.

You don't aggregate, so try a WHERE instead of HAVING.

Upvotes: 0

nacho
nacho

Reputation: 5397

This is because you don´t have to use having (it is used only for aggregated functions), you must use where like this:

 Select eid 
 from employee 
 where ename= "Vikram";

Upvotes: 1

Related Questions