I have the following table
mysql> desc items;
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| code | varchar(255) | YES | | NULL | |
| name | varchar(255) | YES | | NULL | |
| price | float | YES | | NULL | |
| ingredient_id | int(11) | YES | | NULL | |
| ingredient_id2 | int(11) | YES | | 0 | |
| ingredient_id3 | int(11) | YES | | 0 | |
+-------------------+--------------+------+-----+---------+----------------+
and my ingredients table
mysql> desc ingredients;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
and ingredient_id, ingredient_id2, ingredient_id3 columns are foreign keys of ‘ingredients’ table, my requirement is to create a select query to display items and ingredients as follows
select id, code, name, price, name as ingredient_name1, name as ingredient_name2, name as ingredient_name3
But I dont know how to join the same table 3 times, can someone help me to understand this join condition
TRY