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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:54:14+00:00 2026-05-22T21:54:14+00:00

Ive never had to use a query like this before but there must be

  • 0

Ive never had to use a query like this before but there must be away to do it without using 2 queries?

Table : forum_categories

--------------------------------------
-- id ---- parent_id ---- name -------
--------------------------------------
   1          0           namehere1
   2          1           namehere2
   3          0           namehere3
   4          1           namehere4
   5          3           namehere5

I have the id for a sub cat and i want to select the row for the subcat then with the same query select the the row for the parent where parent_id = id for the parent row etc.

Whats the best way to do this?

  • 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-22T21:54:15+00:00Added an answer on May 22, 2026 at 9:54 pm

    You want something like

    select a.id as child_id, a.name as child_name,
    b.id as parent_id, a.name as parent_name
    from forum_categories a
    inner join forum_categories b
    on a.parent_id = b.id
    

    To restrict to your known id, add

    where a.id = knownid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this script daily and never had an issue before now. Ive been
This seems trivial, but I've never had to worry about it before and my
Ive always wondered this but never had the chance to research it. What sort
Ok, I've used locks quite a bit, but I've never had this scenario before.
I've had this problem many times before, and I've never had a solution I
I've never had to use mysqli until today and cannot seem to get this
I've never had much need for programming with databases. Since their use is so
I've never really had the need to use any drag functions until now, so
I've never had to do IPC on Windows before. I'm developing a pair of
I've had several clients ask this, and I've never been able to get or

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.