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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:27:22+00:00 2026-06-01T17:27:22+00:00

I am coding a messaging system, I am trying to select the last 10

  • 0

I am coding a messaging system, I am trying to select the last 10 messages sent in ascending order (Newest on the bottom).

However having an issue in doing this 🙁

This is my current SELECT statement there are over 30 rows in the table that will are available.

SELECT * FROM 
( SELECT * FROM messages ORDER BY addedDate DESC LIMIT 10 ) tb 
WHERE ( senderID = "1" OR receiverID = "1" ) 
AND ( senderID = "3" OR receiverID = "3" ) 
ORDER BY addedDate ASC LIMIT 10

However for some reason this only returns 7 rows, when using a different combination of sender and receiver if there are less rows than i get less than 7 results even though each should give me at least the 10 rows i want.

Is there another method I can use to get the bottom 10 rows that will match:

WHERE ( senderID = "1" OR receiverID = "1" ) 
AND ( senderID = "3" OR receiverID = "3" ) 

but select the bottom 10 in ascending order.

  • 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-01T17:27:23+00:00Added an answer on June 1, 2026 at 5:27 pm

    You should have the WHERE statement in your subquery, not your main query.

    Try this:

    SELECT * FROM 
    ( SELECT * FROM messages
      WHERE ( senderID = "1" OR receiverID = "1" ) 
      AND ( senderID = "3" OR receiverID = "3" )
    ORDER BY addedDate DESC LIMIT 10 ) tb 
    ORDER BY addedDate ASC
    

    And you don’t need that second LIMIT, as you only get 10 results from the subquery.

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

Sidebar

Related Questions

I am coding a messaging system and I don't want to have short IDs
I am currently working on a private messaging system. Right now I'm coding the
background on the topic ok ive been coding a messaging page which users come
I am using JMS Messaging in my java program. My messages are coming from
I am coding a website in PHP and Javascript which implements private messaging functionality,
I'm trying to get IronRuby installed on a Mac and having trouble getting it
I'm coding in C# for the .NET Framework 3.5. I am trying to parse
I'm currently working on my private messaging system for my website and so far
I have been thinking of implementing a PHP messaging system on my site. Would
Coding on Visual C# since a few days ago. Trying to access the elements

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.