0

I have two tables

Categories

ID  PARENT_ID  NAME
1     0        Shopping
2     1        Health

Business_Categories

ID  BUSINESS_ID  CATEGORY_ID  
1    1                1
2    1                2

Now I want below mentioned details

BUSINESS_ID SUBCATEGORY_NAME MAINCATEGORY_NAME

But I don't know how could I do it?

Jaydeep Rajgor
  • 137
  • 1
  • 2
  • 12

1 Answers1

1
select
bus.business_id, cat2.name as subcategory_name, cat1.name as maincategory_name
from 
business_categories as bus
inner join categories as cat1 on bus.category_id = cat1.id
inner join categories as cat2 on cat1.parent_id = cat2.id
Cajun
  • 36
  • 1
  • 6