I need to make a inner join in a mysql table, but it's the same table.
I have a table categories: An example of this table is:
id | id_lingua | id_registro | categoria | nivel
1 1 1 Pastas 0
2 2 1 Folders 0
3 3 1 Carpetas 0
4 1 2 Feminina 1
5 2 2 Women 1
6 3 2 Mujeres 1
nivel is the key that defines whether it is a category or sub category and I need to list these categories and next to specify the parent category level across the field that will contain the id_registro the parent category.
I do not know if I was clear but how do the inner join this table?
the table is:
id id_lingua id_registro categoria nivel
1 1 3 Pastas 0
2 2 3 Folders 0
3 3 3 Carpetas 0
4 1 4 Feminina 3
5 2 4 Women 3
6 3 4 Mujeres 3
and this consult:
SELECT cat.*, parent.categoria as nome
FROM categorias cat
INNER JOIN categorias parent
ON cat.nivel=parent.id_registro
AND cat.id_lingua=2
Return:
id id_lingua id_registro categoria nivel nome
5 2 4 Women 3 Pastas
5 2 4 Women 3 Folders
5 2 4 Women 3 Carpetas