Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:05:24+00:00 2026-06-05T15:05:24+00:00

I have a table with fields user_id and votes . The votes field is

  • 0

I have a table with fields user_id and votes. The votes field is either 1 for an up vote, or 0 for down vote.

What I’d like to do is display the total up votes and total down votes in one query for a specific user.

I was thinking I could maybe use GROUP BY somehow to achieve this, but I don’t know if I can use it with a SUM function somehow?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:05:25+00:00Added an answer on June 5, 2026 at 3:05 pm

    GROUP BY would only be necessary if you wanted the vote count for multiple users; with a single user, one need only specify a WHERE clause:

    SELECT SUM(votes=1) AS upvotes, SUM(votes=0) AS downvotes
    FROM   my_table
    WHERE  user_id = ?
    

    As an aside, you might want to consider having downvotes stored as -1 (instead of 0) in order that the net vote count can easily be calculated as just SUM(votes).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user table 'users' that has fields like: id first_name last_name ...
Say I have a 'user_log' table with the following field: id user_id status_text timestamp
I have one table, t1, which has fileds called userid, week and year fields.
I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_ID,
I have a table with these fields: User_id, User_type, User_address Is it possible to
I have a table name wishlist . In this I have two fields user_id
I have a table of reports that has these relevant fields: user_id (int 11)
I currently have a GAME table with two fields user_id, win win = 1
I have a table called order_list with the following fields order_id user_id item_id count
I have the following schema. Table votes +------------------+--------------+------+-----+---------------------+----------------+ | Field | Type | Null

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.