0

I am trying to access the details from two joined tables in SQL of 5 categories, for one of which I need to run the COUNT function. I am able to access the details, until I run the count function, after which I am limited to a single result. I have also tried using COUNT(*) as... - but this hasn't worked. The code is as follows:

SELECT name, location, grade_1996, COUNT(voter_id)
FROM votes
JOIN congress_members
ON congress_members.id=politician_id
WHERE grade_current < 9;

Please help, thank you.

1
  • Edit your question and provide sample data and desired reult. Commented Feb 26, 2017 at 4:22

2 Answers 2

1

You need a group by. Perhaps this is what you intend:

SELECT name, location, grade_1996, COUNT(voter_id)
FROM votes JOIN
     congress_members
     ON congress_members.id=politician_id
WHERE grade_current < 9
GROUP BY name, location, grade_1996;
Sign up to request clarification or add additional context in comments.

Comments

0

You are missing the GROUP BY clause:

select name,
    location,
    grade_1996,
    COUNT(voter_id)
from votes
join congress_members on congress_members.id = politician_id
where grade_current < 9
group by name,
    location,
    grade_1996;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.