I have a database table which has correlation with 2 different tables, for example:
=== inventory ===
+------------+-----------+
| code | total |
+------------+-----------+
| el_pr_25 | 45 |
| el_pr_11 | 33 |
| mob_tp_x93 | 23 |
| mob_tp_t55 | 33 |
| el_pr_x73 | 25 |
| mob_tp_25 | 22 |
+------------+-----------+
= electricity =
+-----+-------+
| id | name |
+-----+-------+
| 25 | test1 |
| 11 | test2 |
| x73 | test3 |
+-----+-------+
== mobile ==
+-----+----------+
| id | name |
+-----+----------+
| x93 | test 66 |
| t55 | test 222 |
| 25 | test 323 |
+-----+----------+
the main table i want to select is the inventory table, the inventory table is connected to the other table through code column, for electricity table there is a el_pr_ prefix followed by the id of the electricity table and for mobile table the prefix is mob_tp_ is the prefix, i want to select the inventory table with the name column from the electricity and mobile table, for example the result will be like this:
SELECT code,total, ... as name FROM inventory;
=== inventory ===
+------------+-----------+----------+
| code | total | name |
+------------+-----------+----------+
| el_pr_25 | 45 | test1 |
| el_pr_11 | 33 | test2 |
| mob_tp_x93 | 23 | test 66 |
| mob_tp_t55 | 33 | test 22 |
| el_pr_x73 | 25 | test3 |
| mob_tp_25 | 22 | test 323 |
+------------+-----------+----------+
