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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:29:40+00:00 2026-06-10T02:29:40+00:00

I am using the following MySQL query to access the latest 20 messages in

  • 0

I am using the following MySQL query to access the latest 20 messages in a chat log and reverse the order so that the latest message is printed on screen last:

SELECT * 
FROM 
    (
        SELECT
            messageID,
            posterID,
            messageTime,
            message
        FROM
            chat_messages
        /* Subquery is used to get the most recent 20 by messageTime */
        ORDER BY 
            messageTime DESC
        LIMIT 20
    ) subq
/* Reorder the result of the subquery to put them back into ascending order */
ORDER BY 
    messageTime ASC

It works well. The problem is that I am now trying to add groups to the chat functionality. In doing this I have added a further column to the table chat_messages called ‘group’. The main chat log is group 0 so I need to change the above query to access only messages from the main chat log. This is where I am stuck. It appears that MySQL will not allow me to add a where clause within the sub-query. I have tried the following and it did not work:

SELECT * 
FROM 
    (
        SELECT
            messageID,
            posterID,
            messageTime,
            message
        FROM
            chat_messages
        WHERE
            group = '0'
        /* Subquery is used to get the most recent 20 by messageTime */
        ORDER BY 
            messageTime DESC
        LIMIT 20
    ) subq
/* Reorder the result of the subquery to put them back into ascending order */
ORDER BY 
    messageTime ASC

I get this error message (line 58 is the next line after the query):

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in xxxxxxx on line 58

Following what was written on this thread I tried the following, which also did not work:

SELECT * 
FROM 
    (
        SELECT
                (
                    SELECT
                        messageID,
                        posterID,
                        messageTime,
                        message
                    FROM
                        chat_messages
                    WHERE
                        group = '0'
                )
        FROM
            chat_messages
        /* Subquery is used to get the most recent 20 by messageTime */
        ORDER BY 
            messageTime DESC
        LIMIT 20
    ) subq
/* Reorder the result of the subquery to put them back into ascending order */
ORDER BY 
    messageTime ASC

How can I make the query only access messages from group 0? I just don’t understand how it is not working?

Thank you,
Joe

  • 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-10T02:29:41+00:00Added an answer on June 10, 2026 at 2:29 am

    GROUP is a reserved word for MySQL, place backticks ` around it.

    SELECT * 
    FROM 
    (
         SELECT messageID,
              posterID,
              messageTime,
              message
         FROM chat_messages
         WHERE `group` = '0'
            /* Subquery is used to get the most recent 20 by messageTime */
         ORDER BY  messageTime DESC
         LIMIT 20
     ) subq
    /* Reorder the result of the subquery to put them back into ascending order */
    ORDER BY  messageTime ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following InnoDB tables in mysql to describe records that can
I'm using the following mysql query to return some data from my database. Currently
I am using the following mysql query for grouping referrersource. SELECT referrersource,count(referrersource) as counts
I ran a MySQL query from command line using the following: nohup mysql --user=root
I am using following prepared statement : Class.forName(com.mysql.jdbc.Driver); con=DriverManager.getConnection(jdbc:mysql://localhost:3306/mysql,root,root); String query=select ename from ?
I'm using following code but cannot return data from MySQL. This is the output:
I am using the following code to update my mysql table where both moving50
I'm using the following to insert company data into a mysql table. Is is
I am using the following code to connect to a MySQL DB and simply
I am using a MySQL table called login with the following structure: loginid, username,

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.