0
SELECT
tblOrgao.eleicao_id as IdEleicao,
tblCargo.orgao_id as IdOrgao,
tblOrgao.orgao as Orgao,
tblCargo.id as IdCargo,
tblCargo.cargo as Cargo,
tblLista.lista as NomeLista,
tblListaCandidatos.candidato_id as NumberMembro
FROM
tblOrgao inner join
tblCargo on tblCargo.orgao_id = tblOrgao.id,
tblListaCandidatos LEFT JOIN
tblLista ON tblLista.id = tblListaCandidatos.lista_id
WHERE tblOrgao.eleicao_id = '20' AND tblLista.lista = 'A'
The member number is appearing 3 times repeated
I’ve tried using one Group by tblCargo.id
I tried so
SELECT
tblOrgao.eleicao_id as IdEleicao,
tblCargo.orgao_id as IdOrgao,
tblOrgao.orgao as Orgao,
tblCargo.id as IdCargo,
tblCargo.cargo as Cargo,
tblLista.lista as NomeLista,
tblListaCandidatos.candidato_id as NumberMembro
FROM
tblOrgao inner join
tblCargo on tblCargo.orgao_id = tblOrgao.id,
tblListaCandidatos LEFT JOIN
tblLista ON tblLista.id = tblListaCandidatos.lista_id
WHERE tblOrgao.eleicao_id = '20' AND tblLista.lista = 'A'
Group by tblCargo.id;
Msg 8120, Level 16, State 1, Line 2 Column 'tblOrgao.eleicao_id' is invalid in the select list because it is not contained in either an Aggregate Function or the GROUP BY clause.
What to get is the following output
After that recommendation was like this Output and either way I really need the data from tblListaCandidatos.candidato_id as Numbermembro to appear in this query
– Amadeu Antunes
You could post as these doing group by. in that select there is no group by any
– Elton A. Pering
tbllistacandidates have organ id field?
– Rodrigo Zem
no, you have the job id
– Amadeu Antunes
Instead of just presenting the SQL command explain what you want to get.
– anonimo
Not knowing the structure of the tables becomes complicated. If you have how to post it would be clearer.
– Rodrigo Zem
Note that, for example for Numbermembro=1001, there is more value for the organ field. Why should one value be chosen over another? Since you are not using any aggregation function maybe the use of the GROUP BY option is not the most suitable for your problem.
– anonimo
What should I use to get the values that way?
– Amadeu Antunes