Jump to content

Join a table with itself?


beyzad

Recommended Posts

Hi there.

 

I have a table named `cat` that looks like this:

id	|name		|parent
--------+---------------+------
1	|cat1		|0
--------+---------------+------
2	|cat2		|0
--------+---------------+------
3	|subcat1	|1
--------+---------------+------
4	|subcat2	|1
--------+---------------+------
5	|subsubcat1	|3
--------+---------------+------

I need to export something like this with only 1 query if it is possible:

id	|name		|parent(name)
--------+---------------+------------
1	|cat1		|NULL
--------+---------------+------------
2	|cat2		|NULL
--------+---------------+------------
3	|subcat1	|cat1
--------+---------------+------------
4	|subcat2	|cat1
--------+---------------+------------
5	|subsubcat1	|subcat1
--------+---------------+------------

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/294446-join-a-table-with-itself/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.