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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:04:57+00:00 2026-05-11T09:04:57+00:00

I have a MySQL table called bb_posts used by a bbPress forum. It has

  • 0

I have a MySQL table called bb_posts used by a bbPress forum. It has an autoincrement field called topid_id and another field called topic_poster.

I’m trying to write a function that finds the ‘next post by the same author’. So, for instance, say the user is on a particular page that displays topic 123. If you do a SQL query:

SELECT * FROM `bb_topics` WHERE `topic_poster` = 5 ORDER BY `topic_id` ASC 

This might return the following rows:

 topic_id    topic_poster 6           5 50          5 123         5 199         5 2039        5 

What I’d like to do is write a SQL query that returns these two rows:

 topic_id    topic_poster 50          5 199         5 

This would be the row PRIOR to the row with topic_id of 123, and the row AFTER that row.

If it’s too hard to do this in one query, it’s definitely OK to break this up into two queries…

I’d like to avoid doing the whole SQL query (‘SELECT * FROM bb_topics WHERE topic_poster = 5′) and looping through the results, because the result set is sometimes huge.

Is this possible? 🙂

  • 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. 2026-05-11T09:04:57+00:00Added an answer on May 11, 2026 at 9:04 am

    Next one:

    SELECT * FROM `bb_topics`        WHERE `topic_id` =        (select min(`topic_id`) FROM `bb_topics` where `topic_id` > 123          and `topic_poster` = 5) 

    Previous one:

    SELECT * FROM `bb_topics`        WHERE `topic_id` =        (select max(`topic_id`) FROM `bb_topics` where `topic_id` < 123          and `topic_poster` = 5) 

    Both:

    SELECT * FROM `bb_topics`        WHERE `topic_id` =        (select min(`topic_id`) FROM `bb_topics` where `topic_id` > 123                      and `topic_poster` = 5)       or `topic_id` =        (select max(`topic_id`) FROM `bb_topics` where `topic_id` < 123                         and `topic_poster` = 5) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table called pollOfTheWeek. It has a column pollDate of type
I have a MySQL table called privatemessage with a primary key field called messageid.
I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .
I have a date and time column in my mysql table called start_date and
I have a MySQL table called items that contains thousands of records. Each record
I have a mysql table called RATING with this structure: ID, USERNAME, RATING, RATER,
I have a MySql table called reviews which stores a lot of product reviews,
I have a mySQL table called test: create table test( locationExpect varchar(120) NOT NULL;
I have this mysql table called comments which looks like this: commentID parentID type
I have a MySQL table called invoice_prod : id | qte | price |

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.