I did not find anything about this.
Here is my request:
SELECT p.*, pa.*, a.*
FROM produit p
LEFT OUTER JOIN produit_attribut pa
ON p.id=pa.id_produit
LEFT OUTER JOIN attribut a
ON a.id=pa.id_attribut
ORDER BY p.id,a.id;
But the problem is that it returns columns
with the same name:
+----+------------+-----+------------+-------------+------+-----+----+----+
| id | titre | desc| id_produit | id_attribut | id | desc| val| abb|
+----+------------+-----+------------+-------------+------+-----+----+----+
| 1 | Anchois | Sauc| 1 | 1 | 1 | Nomb| 2 | Nb |
| 2 | Fromage | Sauc| 2 | 1 | 1 | Nomb| 2 | Nb |
| 3 | Mozzarella | Sauc| 3 | 1 | 1 | Nomb| 2 | Nb |
| 4 | Jambon | Sauc| 4 | 1 | 1 | Nomb| 2 | Nb |
| 5 | Roquefort | Sauc| 5 | 1 | 1 | Nomb| 2 | Nb |
| 6 | Royale | Sauc| 6 | 1 | 1 | Nomb| 2 | Nb |
I would like to know if there is a way to rename all the fields of the table, something that might look like (I know the following sql does not work):
SELECT p.* as p*, pa.* as pa*, a.* as att*
FROM produit p
LEFT OUTER JOIN produit_attribut pa
ON p.id=pa.id_produit
LEFT OUTER JOIN attribut a
ON a.id=pa.id_attribut
ORDER BY p.id,a.id;
By the way, I know that I can do something like:
SELECT
p.id AS p_id,
p.titre AS p_titre,
p.description AS p_description,
p.prix AS p_prix,
p.text_detail AS p_text_detail,
p.img_petite AS p_img_petite,
p.img_grande AS p_img_grande,
pa.id_produit AS pa_id_produit,
pa.id_attribut AS pa_id_attribut,
a.id AS a_id,
a.description AS a_description,
a.valeur AS a_valeur,
a.abbreviation AS a_abbreviation
FROM produit p
LEFT OUTER JOIN produit_attribut pa
ON p.id=pa.id_produit
LEFT OUTER JOIN attribut a
ON a.id=pa.id_attribut
ORDER BY p_id,a_id;
But I would like to avoid this.
I want the query to be general, because I will use this query in Php and its common CRUD component (and nested table).
Is there any way?