I'm new to databases and mysql. I'm having a difficult time even deciding exactly what the problem I'm facing is and don't really know what the relevant google search would be. So forgive me if this is a mind-blowingly retarded question. I have two tables tabs
and cats
.
tabs
is like this:
name | order
tab1 | 3
tab2 | 0
tab3 | 1
tab4 | 2
cats
is like this:
name | tab_name
cat1 | tab3
cat2 | tab3
cat3 | tab1
cat4 | tab1
cat5 | tab1
I guess it's a one-to-many relationship tabs-to-cats. My question is how can I structure a query that will return only distinct tab names, each with all of its associated cats? I can get a result with all the cats and many duplicate tabs. Or I can get only distinct tabs but only one cat per tab. Maybe I should just be testing for duplicate tabs with my php code? Or querying tabs then querying all the cats for each tab? It just seems like there has got to be a more direct way. I'm currently using this query:
SELECT t.name AS tab, c.name AS cat FROM tabs t
LEFT JOIN categories c
ON t.name=c.tab_name
ORDER BY t.order;