patovega
patovega

Reputation: 343

Invalid use of group function MYSQL

i have a problem with this query:

select distinct(id_soc)
FROM table
WHERE 
id_soc = '1234567'
AND TIMESTAMPDIFF( MONTH ,
MAX(date_ven), DATE_ADD(MAX(date_ven),INTERVAL 1 MONTH)) = 1
group by id_soc

the error is: #1111 - Invalid use of group function

but i dont know the problem, can i help me?

thanks.

Upvotes: 0

Views: 353

Answers (2)

Sajuna Fernando
Sajuna Fernando

Reputation: 1384

Your results are already unique when you group then. So you do not need DISTINCT

select id_soc
FROM table
WHERE 
id_soc = '1234567'
AND TIMESTAMPDIFF( MONTH ,
MAX(date_ven), DATE_ADD(MAX(date_ven),INTERVAL 1 MONTH)) = 1
group by id_soc

Upvotes: 0

NoChance
NoChance

Reputation: 5752

Don't use Distinct with Group By. Remove Distinct from SELECT.

Upvotes: 2

Related Questions