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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:19:19+00:00 2026-05-24T23:19:19+00:00

I have 2 tables: Table A is a category table. Columns are cid, catname

  • 0

I have 2 tables:

Table A is a category table. Columns are cid, catname.

Table B is a relationship table. Columns are cid, parent (parent is another cid).

Here’s where I am so far:

"SELECT c.cid, c.catname AS catname, r.parent AS parent FROM tableA AS c JOIN tableB AS r ON r.cid=c.cid";

I know I’ll get 3 columns (2 from tableA and one from tableB) but I also want to get the catname value from the parent in tableA If I were to do a second query, it would look like this (assuming we put the result into a $row variable):

"SELECT catname FROM tableA WHERE cid='".$row['parent']."'";

That way I can display it as text.

What do I add, and where? Is there a second JOIN?

  • 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-24T23:19:20+00:00Added an answer on May 24, 2026 at 11:19 pm

    You can join a table multiple times:

    SELECT a.cid AS acid, a.catname AS aname,
           b.cid AS bcid, b.catname AS bname
    FROM relationships AS r
         JOIN categories AS a ON (r.cid = a.cid)
         JOIN categories AS b ON (r.parent = b.cid)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Two tables like this: Table categories: columns: id, name, parent 1, Foods,
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged
My prob in brief: I have two tables namely category and product. table: category
I have three tables Category, Movies and RelCatMov Category-table categoryid, categoryName 1 thriller 2
I have a structure where the main table is USER, other tables include CATEGORY
Now I have 4 tables: table categories: -id -category table products: -id -product -price
I have a CGridView with columns from a table product => {'product_id','category_id',...} I have
I have a table that has three columns: Category, Timestamp and Value. What I
Let's say I have a table, category , which has 3 columns, id ,
I have a category table with two columns category_id and name . I have

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.