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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:06:34+00:00 2026-05-30T04:06:34+00:00

| postid | ref_postid | title | | 1 | 0 | Title 1

  • 0
| postid | ref_postid | title   |
| 1      | 0          | Title 1 | 
| 2      | 1          |         | 
| 3      | 1          |         | 
| 4      | 0          | Title 2 | 
| 5      | 4          |         |

It´s a table for a discussion forum. When ref_postid = 0, that means it is a main post. When ref_postid is not 0 it is a answer and references to a postid, see table example above. (Only main posts has a title.)

I want to select all rows in the table, but the problem is that I want to display the title for the discussion an answer refers to.

Example: Let´s say I want the row where postid = 2, I also want to get “Title 1” which is the name of the discussion.

I tried doing it with CASE but I just got errors. I´m not very good at this. Is it doable with one query? Or will I have to use two queries?

Thanks for your help!

  • 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-30T04:06:36+00:00Added an answer on May 30, 2026 at 4:06 am
    select ifnull(q.title, a.title) title, ... (other columns)
    from posts a
    left join posts q on a.ref_postid <> 0 and a.ref_postid = q.postid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CREATE TABLE Post ( postID - PK memberID title thread . . . reported
Say I have: create table Post( PostID int not null constraint PK_Post primary key
Say we have a table table posts +---------+-----------+--------------------------------+ | postId | title | status
CREATE TABLE BlogPosts ( PostID INT PRIMARY KEY not null, PostTitle NVARCHAR , BlogID
Here's my table: dbo.Posts PostId (IDENTITY, PK) Subject UniqueUri (NVARCHAR(350), NOT NULL) When i
im using doctrine-project and i have 3 tables table 1: post -------------- postid ,
I have a minimal case as follows:- Table Posts PostID - PK PostDateTime Table
I have this: Post post = GetPost(postID); if (post.User.UserID == userID) return true; And
tables: POSTS (id title data userid) CONNECTIONS( postid userid) I want to get rows
My query is: SELECT temp.pid FROM (SELECT postid, date FROM swapping AS s, post

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.