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'
O numero de membro está a aparecer 3 vezes repetido
Já tentei usar um Group by tblCargo.id
Tentei assim
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.
O que pertendo obter é o seguinte output