I have table look like this in phpmyadmin:
+-----------+-----------------+-------------------+
|nom_ele_id | nom_ele_title | nom_ele_parent_id |
+===========+=================+===================+
| 7060 | STANDARD | NULL |
| 6953 | SOL | 7060 |
| 6957 | type de sol | 6953 |
+-----------+-----------------+-------------------+
I would like to have "nom_ele_tile" of parent with my "nom_ele_parent_id".
I try this:
SELECT a.nom_ele_id, a.nom_ele_title, b.nom_ele_title AS 'nom_parent'
FROM `immo_nomenclature_element` AS a
LEFT JOIN `immo_nomenclature_element` AS b
on a.`nom_ele_parent_id` = b.`nom_ele_id`
but with this request i can’t use WHERE nom_ele_title
="type de sol" for exemple. and I get my entire table like this:
+-----------+-----------------+-------------------+
|nom_ele_id | nom_ele_title | nom_parent |
+===========+=================+===================+
| 7060 | STANDARD | NULL |
| 6953 | SOL | STANDARD |
| 6957 | type de sol | SOL |
+-----------+-----------------+-------------------+
2
Answers
I am not sure if I get your question right.
You only want a nom_parent if the nom_ele_title="type de sol" , right?
Then you can just add a "and nom_ele_title="type de sol" to your join condition.
you just need to add
where
clause: