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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:29:21+00:00 2026-05-13T00:29:21+00:00

Here is my mysql query below. Through many helpful questions and comments I am

  • 0

Here is my mysql query below. Through many helpful questions and comments I am almost at the end of my journey. The idea behind this query is a user submits a link, the application inserts two rows, one into links and another into votes (a default vote, why wouldn’t a user vote for their own submission?) Then every vote is just another row in the votes table with a either a karma_up or karma_down equaling 1 (soon to be changed to karma_delta to save on the extra column. I also have the popularity algorithm in there which seems to be b0rking my query. Running the below query warrants me this error.

#1247 - Reference 'karma' not supported (reference to group function)

The whole point of the majority of this query is to get the karma

SELECT links.*, (SUM(votes.karma_up) - SUM(votes.karma_down)) AS karma
FROM links, votes
WHERE links.id = votes.link_id
GROUP BY votes.link_id
ORDER BY (karma - 1) / POW((TIMESTAMPDIFF(HOUR, links.created, NOW()) + 2), 1.5) DESC
LIMIT 0, 100

Without the popularity algorithm at the ORDER BY part the query runs perfectly, adding the sum’ed up karma from the votes table and tacking on an extra column with it’s value.

  • 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-13T00:29:21+00:00Added an answer on May 13, 2026 at 12:29 am

    The problem is here:

    `ORDER BY karma...
    

    You can’t order by something which is defined as an alias. Try this:

    `ORDER BY ((SUM(votes.karma_up) - SUM(votes.karma_down)) - 1) / POW((TIMESTAMPDIFF(HOUR, links.created, NOW()) + 2), 1.5) DESC`
    

    Hopefully the DB can figure out not to evaluate it twice. If not, use an inner select without the order by first to create the alias, then use another select to order.

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

Sidebar

Related Questions

Hi im having an interesting problem. Update: From the comments im getting below this
I'm having a little problem with this MySQL query. I've already used an suggestion
I'm the second dev and a recent hire here at a PHP/MySQL shop. I
I'm having some trouble updating a row in a MySQL database. Here is the
Pretty straightforward stuff, here -- I'm just not good enough with mysql to understand
Here is the issue I am having: I have a large query that needs
Here is my mysql table scheme; status table // has statusID, userID,date, subject, date
I've seen a million of these threads here already, and read through every single
please I have the same problem as I found here MySQL - Selecting data
This is beyond both making sense and my control. That being said here is

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.