Db2 select query with group by clause throws error?

user3398326

I want to get Distinct values of SERIAL_NUM and EMP_NAME but the below query throws an error.

SELECT SERIAL_NUM,EMP_NAME,NOTESID FROM DB2INST1.EMP_HC 
GROUP BY 
SERIAL_NUM,EMP_NAME,NOTESID 
HAVING   
FUNC_VP ='Bob '  AND 
VICE_PRES ='Bob'  AND 
DIRECTOR ='Michael'  AND 
THIRD_LINE ='Linda ' 

error

DB2 SQL Error: SQLCODE=-119, SQLSTATE=42803, SQLERRMC=FUNC_VP, DRIVER=3.63.123

a_horse_with_no_name

If you want "distinct values of SERIAL_NUM and EMP_NAME" you need to tell the database which notesid to pick if there are multiple combinations of serial_num and emp_name. If you don't care which notesid you get, you can e.g. use min()

SELECT serial_num,
       emp_name,
       min(notesid) as notesid
FROM db2inst1.emp_hc 
WHERE func_vp ='Bob '  
  AND vice_pres ='Bob'  
  AND director ='Michael'  
  AND third_line ='Linda'  
GROUP BY serial_num,emp_name

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Mysql query error :SELECT list is not in GROUP BY clause and contains nonagregated column, incompatible with sql_mode=only_full_group_by

How to store the result of a select query into a variable(IBM DB2)?

SELECT COUNT query throws error in MySQL

sql query error-invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

MYSQL INNER JOIN FUNCTION ERROR Expression #2 of SELECT list is not in GROUP BY clause

DB2 query with subqueries and multiple group by statements

SELECT a column not in GROUP BY clause

Query optimization with in (select ...) clause

SQL Query Group by Clause

Error:A query body must end with a select clause or a group clause

SQL select query with not not in clause

SQL Query Error in Group By and Order By Clause

Java select query throws an error on DB2 database?

Getting DB2 SQL Error while firing a select query using Worklight 6.1.0?

Where clause in complex linq query giving the following error "A query body must end with a select clause or a group clause linq"

db2 select query with between and partition

db2 select statement with group and sum

DB2 SELECT EXCEPT with WHERE clause

A Database Error Occurred Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column

SQL SELECT query in DB2

Error regarding aggregate functions or the group by clause in a FOR XML Path query

Oracle Error message: not a GROUP BY expression when adding another 'Select' clause

Mysql2::Error: Expression #5 of SELECT list is not in GROUP BY clause and contains nonaggregated column

display column in select query not added in group by clause

How to fix column must appear in group by clause error in sql select

Error executing dynamic select query inside a stored procedure in IBM DB2

IN clause in select query with a subquery

Resolve Error SELECT list is not in GROUP BY clause and contains nonaggregated column

DB2 Select Query for CLOB data not working via Linux