Display exclude link only if there are no child categories

3

I have a database with the following columns:

|id|id_pai|nome_categoria|
+--+------+--------------+
|01|   0  | Eletronicos  |
|--+------+--------------+
|02|   01 | Notebook     |
|--+------+--------------+
|03|   0  | Livros       |
+--+------+--------------+
|04|  03  | Romance      |
+--+------+--------------+

I want to return a table in html with name only of the parent category and a link to delete, but the link can only appear if the category does not have a child category.

    
asked by anonymous 24.02.2016 / 15:09

1 answer

1

I think it would look something like:

SELECT id, nome_categoria
FROM categoria
WHERE id NOT IN
    (SELECT DISTINCT id_pai
     FROM categoria);
    
28.03.2016 / 15:07