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 3431904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:23:01+00:00 2026-05-18T07:23:01+00:00

I am creating a bulletin board application. Each bulletin can be liked or disliked

  • 0

I am creating a bulletin board application. Each bulletin can be liked or disliked by users of the site.To keep track of the likes and dislikes I have created the following database table

id  user_id   bulletin_id   like_dislike
1   1         1             1
2   1         2             0
3   3         1             1
4   2         1             0

In the like_dislike column 1 means ‘Like It’, 0 means ‘Don’t like it’
I know how to ask.
– How many times was bulletin 1 liked (2)
– How many times was bulletin 1 disliked (1)

But How do I do a query to ask those two questions at the same time? That is, how many times was bulletin 1 liked and disliked

liked  disliked
2      1

I have tried the query

  SELECT count(like_dislike) AS likes, count(like_dislike) AS dislikes FROM bulletins_ld
where bulletins_id = 1 AND likes = 1 AND dislikes = 0

but all I get is two twice which is not surprising.
The only solution I can think of is having a separate like and dislike column

  • 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-05-18T07:23:02+00:00Added an answer on May 18, 2026 at 7:23 am

    You can do this with an aggregate query, using opposing conditions on the single like_dislike column (I am assuming below that a ‘1’ in that column means ‘liked’).

    SELECT bulletin_id, 
           SUM(CASE WHEN like_dislike = 1 THEN 1 ELSE 0 END) AS likes, 
           SUM(CASE WHEN like_dislike = 0 THEN 1 ELSE 0 END) AS dislikes
    FROM bulletins_ld
    GROUP BY bulletin_id
    

    Update: As per the discussion in the comments below, the like/dislike column could be normalized into its own table, like so (example deliberately silly…):

    CREATE TABLE how_user_feels(
        feeling_id INT,
        feeling_desc VARCHAR(20)
    )
    
    INSERT INTO how_user_feels(feeling_id, feeling_desc) VALUES
    (0, 'Undecided'),
    (1, 'Likes It'),
    (2, 'Could Do Without It')
    

    The Likes_Dislikes column in the Bulletin table is then replaced by the foreign key feeling_id, with a default to 0. Let’s say that you then enter a record in this table when a user first views a bulletin, making them “Undecided” by default, and update that record when they vote on the bulletin. You could query the results like so:

    SELECT bulletin_id, 
           SUM(CASE WHEN feelings_id = 1 THEN 1 ELSE 0 END) AS likes, 
           SUM(CASE WHEN feelings_id = 2 THEN 1 ELSE 0 END) AS dislikes,
           SUM(CASE WHEN feelings_id = 0 THEN 1 ELSE 0 END) AS doesnt_seem_to_care
    FROM bulletins_ld b
    INNER JOIN how_user_feels h ON b.feeling_id = h.feeling_id
    GROUP BY bulletin_id
    

    Keep in mind, this is just one approach, and may not be useful in your case. But if you ever decided to change or expand the model by which a user expresses their feelings for a bulletin, say to a five-star rating system, you could do that without changing the database schema – just alter the records in the how_user_feels table, and the associated queries.

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

Sidebar

Related Questions

I'm creating a bulletin board system, and now I'm implementing a 'delete topic' feature
Creating a login page in xcode 4.2 I have the users fill out information
I'm creating a quoting system within a custom bulletin board. What I need to
Creating a web interface so our helpdesk can create users and setup some of
Creating a ruby on rails site and recently added: <% if (?can :manage, :table)
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating an installer for possible remote systems so that if they do not have
Creating a site in with FrogCMS and using alot of jquery to create an
Creating a widget for my site. Check it out at http://bit.ly/w42SC4 . Looks good
Creating an Iphone application, I used to perform INSERT QUERY on different databases. But

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.