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

  • Home
  • SEARCH
  • 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 8305457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:07:13+00:00 2026-06-08T18:07:13+00:00

I have a table of node likes, which looks roughly like this: lid nid

  • 0

I have a table of node likes, which looks roughly like this:

lid nid uid type
1   23  3   like
2   23  1   like
3   49  3   dislike
4   11  6   like

lid = unique ID for this table, nid = “node” (content) ID, uid = user ID and type is self explanatory.

With this query:

SELECT nid, COUNT(lid) AS score, type
FROM node_likes
INNER JOIN users ON node_likes.uid = users.uid
GROUP BY nid, type

I can get each node with its like and dislike scores. The inner join is irrelevant; some (dis)likes are from users that no longer exist, and the join is to eliminate them.

The result looks like this:

nid score type
307 4     like
307 1     dislike
404 24    like

How can I then sub-group this query by type, and return the top-scoring node ID for each “like” type (like/dislike)?

Ie.

nid score type
404 24    like
307 1     dislike
  • 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-08T18:07:14+00:00Added an answer on June 8, 2026 at 6:07 pm
    SELECT
        SUBSTRING_INDEX(GROUP_CONCAT(nid ORDER BY likes DESC),',',1) as most_likes_nid,
        MAX(likes) as most_likes,
        SUBSTRING_INDEX(GROUP_CONCAT(nid ORDER BY dislikes DESC),',',1) as most_dislikes_nid,
        MAX(dislikes) as most_dislikes
    FROM (
        SELECT 
            nid,
            COUNT(IF(type = 'like', 1, null)) as likes,
            COUNT(IF(type = 'dislike', 1 ,null)) as dislikes
        FROM node_likes
        GROUP BY nid 
    ) as t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that look like this: node: NID Name 1 Chicago 2
I have a Standard table, which sotres parent, child category relationship...like this. id, parent,
I have 3 tables which look like this: Location Node Sektor ----- ------- -------
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
I have a table which contains data about which node has been visited. It
I have a data-structure (in plist) that looks something like this: What i have
I have a mysql table like this: I'm trying to get a list of
I have an xml file which looks like the below example <Ids> <Id> <set>ai</set>
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have XML column in my table which can contain XML like these 2

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.