I have the following query:
SELECT funcionario.*, emprego.data_admissao, emprego.data_saida, emprego.data_dispensa
FROM funcionario,emprego,empresa
WHERE empresa.id = emprego.id_empresa
AND funcionario.id = emprego.id_funcionario
AND emprego.data_admissao IS NOT NULL
AND empresa.id = 2 GROUP BY funcionario.id
It is displaying the following error:
# 1055 - Expression # 28 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'portfolio.employ.data_admissao' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode = only_full_group_by
Then I add the group by of 'data_admissao' and the other field to not the error:
SELECT funcionario.*, emprego.data_admissao, emprego.data_saida, emprego.data_dispensa
FROM funcionario,emprego,empresa
WHERE empresa.id = emprego.id_empresa
AND funcionario.id = emprego.id_funcionario
AND emprego.data_admissao IS NOT NULL
AND empresa.id = 2
GROUP BY funcionario.id, emprego.data_admissao, emprego.data_saida, emprego.data_dispensa
So it works, but I wanted the items to be grouped by 'official.id' and when I run this query the records are repeated.
I would like the records to focus grouped by 'official.id' only, when executing this second query it works, but 'official.id' is repeated.
Update
I removed the "*" from the query just so it is easy to show the result here.
I performed:
SELECT funcionario.id, emprego.data_admissao, emprego.data_saida, emprego.data_dispensa FROM funcionario,emprego,empresa WHERE empresa.id = emprego.id_empresa AND funcionario.id = emprego.id_funcionario AND emprego.data_admissao IS NOT NULL AND empresa.id = 2 GROUP BY funcionario.id, emprego.data_admissao, emprego.data_saida, emprego.data_dispensa
Result: