I'm creating a script that is designed to query a list of posts by selecting a category, sub category and another sub, or by selecting all.
The problem is that when I want to show 'all' posts I need to create 3 queries for each post (to convert the category number into name).
Is there a way to make it more optimized?
Tables structure:
posts:
- id (int)
- main_cat (main category) (int)
- sub_cat (sub category) (int)
- sub_sub_cat (sub to the sub) (int)
- description (varchar)
main_cat:
- id (int)
- name (varchar)
sub_cat:
- id (int)
- relation (int) (id of the main_cat)
- name (varchar)
sub_sub_cat:
- id (int)
- relation (int) (id of the sub_cat)
- name (varchar)
Thanks in advance.