2
List Categories with Subcategories of the same table with another table
I have the following tables:
So far I believe the modeling is ok, right?
Then in the result I would like to search the following fields:
id_manual | titulo | arquivo | downloads | id_categoria | id_subcategoria | categoria | subcategoria -
Since I would not like to concatenate the category and subcategory fields.
I am even doing the merging of the two tables, but the fields are not getting right, what I would like is that in the category field, the name of the category and if you have subcategory the name of the subcategory is in the subcategory field, therefore this for the fields id_categoria
and id_subcategoria
.
How could I do this without concatenating the fields (doing with separator fields)? or just filtering using PHP?
I would like to do only one Query with Mysql for this, if possible.
Possible duplicate of Sort by category
– Guilherme SpinXO
@Guilhermespinxo How could it be done without concatenating the result as in the image 2 I posted? worth
– Marcelo Garbin
How do you mean concatenate the result? Explain it better so I can try to help you.
– Guilherme SpinXO
@Guilhermespinxo in the post you mentioned you use a Sub-select which returns a column with multiple records using Group_concat, what I would like is for you to return the two results in separate columns, example: return the category name and subcategory in separate fields. I don’t know if that would be possible. Do you have any idea?
– Marcelo Garbin
You speak of subcategory but I have not seen this field or ID in both tables, I only saw id_category and id_categoria_pai. Where subcategory is?
– Edson Horacio Junior