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 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

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try: XmlDocument doc = new XmlDocument(); doc.Load(url); doc.Save(filename); It really… May 11, 2026 at 10:42 pm
  • Editorial Team
    Editorial Team added an answer Print "\\n" – "\\" produces "\" and then "n" is… May 11, 2026 at 10:42 pm
  • Editorial Team
    Editorial Team added an answer SSL, attachments and IE are a horrible mix. This is… May 11, 2026 at 10:42 pm

Related Questions

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,
Heres my problem. I have a mysql table called quotes. In one of the
My problem involves searching a MySQL table for a list of matching city names

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.