Mateusz Rasiński
Mateusz Rasiński

Reputation: 1206

Select SUM() throws "Column not found" exception [42122-193] in H2

The execution of the following statement:

SELECT SUM(p.price)
FROM Product p

via JDBC on an embedded H2 database throws exception:

org.h2.jdbc.JdbcSQLException: Column "price" not found [42122-193]

How can I make it work?

Upvotes: 0

Views: 556

Answers (1)

Mateusz Rasiński
Mateusz Rasiński

Reputation: 1206

You have to use an alias for the column used in SUM():

SELECT SUM(p.price) as price
FROM Product p

Beware! The alias has to be named exactly as the column.

Upvotes: 1

Related Questions