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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:29:22+00:00 2026-05-20T10:29:22+00:00

I have a table with the following columns: user_id, key, value, and flag. The

  • 0

I have a table with the following columns: user_id, key, value, and flag. The SELECT, FROM, WHERE, GROUP BY and ORDER BY work by themselves as expected. It’s when I try to add the key to the table, I get an errors that says to check my syntax. The key is the question and the value are the answers. I want a result that shows all the questions with all possible answers and a count of how often that answer occurred.

SELECT value AS 'Answer', count(*) AS 'Total Votes'
FROM survey_data sd
INNER JOIN (SELECT key FROM sd GROUP BY key) T1 ON T1.key = sd.key
WHERE flag != 1
GROUP BY value
ORDER BY 'Total Votes' DESC

What am I missing here?

As a side note, when I run this query without the INNER JOIN, the result is not ordered DESC by ‘Total Votes’ — does anyone know why or what the problem might be?

Thanks,
Ryan

  • 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-20T10:29:23+00:00Added an answer on May 20, 2026 at 10:29 am

    key is a reserved word.

    http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

    put it within backticks (alt+96) or rename your field

    edit. If you use an alias with more than one word you have to use backtick too.
    So change your order by clause in

    order by total votes desc without quotes

    Put backtick before and after total votes. I don’t see them in my post or even better change your field alias with a single word.

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

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have a table with with essentially three columns: user_id, setting, and value. I'm
I have a table with the following columns: A B C --------- 1 10
I have a pictures table that has the following columns: PICTURE_ID int IDENTITY(1000,1) NOT
I have the following code, I'm trying to get a table with 4 columns
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged
I have already googled for this I have a Table with following structure in
I have the following table relationship in my database: Parent / \ Child1 Child2

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.