I am having a problem trying to write a query to pull what would normally be a JOIN into the result set. It's actually a column reference to another record within the same table.
My tables with their columns:
The parent_category column refers back to category_id of a different record within the same table
My query:
My hypothetical result:
I need the get the category_name of the parent_category to show up as the name (not the category id number)
I am assuming this would have to be represented as a subquery within the main query of some sort but I'm having a difficult time conceptualizing it.
The circular reference of this is making my head explode.
My tables with their columns:
Code:
business_table
business_id
business_name
category_id
category_table
category_id
category_name
parent_category
My query:
Code:
SELECT * FROM business_table
JOIN category_table
ON business_table.category_id = category_table.category_id
ORDER BY business_id DESC LIMIT 3
Code:
-----------------------------------------------------------------------------------------------
| business_id | business_name | category_id | category_id_1 | category_name | parent_category |
-----------------------------------------------------------------------------------------------
| 011 | Smith Plumbing| 13 | 13 | Plumbers | 10 |
| 010 | Hair Care Zone| 22 | 22 | Salons | 03 |
| 008 | Taco Bell | 45 | 45 | Mexican Food | 06 |
-----------------------------------------------------------------------------------------------
I am assuming this would have to be represented as a subquery within the main query of some sort but I'm having a difficult time conceptualizing it.
The circular reference of this is making my head explode.