this is the company table
this is the category table
how do i write a query such that it will select one distinct category and list all the companies that belongs to it. e.g school i.e category_id= 1 has two companies that belongs to it such as (Dolly, Abbey scaffold, AP). Art i.e category_id=2 has one company (Blue script); this is the query that i have
$query="SELECT distinct company.id, company.company_name, category.category_name FROM company INNER JOIN category ON company.category_id =category.id ";
the query works fine but it keeps repeating the category_name that has many companies belonging to it. i want it to show category_name once and display the company that belongs to it under
select t1.*, t2.company_name
(Select id, category_name
from category) t1
left join
(select category_id, company_name
from company) t2
on t1.id=t2.category_id