Note . If you are looking for a solution to your problem, and you are attracted here, this probably will not help you. If you are not analyzing a single SQL query for an error, since in fact the error may exist in the next query, without your knowledge, this question may not help you. I am just warning you now because none of the data presented in this question actually leads to an answer.
To expand the database table regular_ruleswithout changing the table itself, I created an additional table ( extended_rules), whose PK is also FK before regular_rules. Then I can place any new columns in extended_rules, and then at any time when I load a record from it, I just need to join it with regular_rules, in order to treat it as if it were a complete object. Thus, as you can see, these two tables have a one-to-one relationship.
However, it regular_rulesalso has a one-to-many relationship with another table ( rule_coupons), which should also be combined.
So I have the following query:
SELECT `main_table`.*, `primary_coupon`.`code`, `regular_rules`.*
FROM `extended_rules` AS `main_table`
LEFT JOIN `rule_coupons` AS `primary_coupon`
ON main_table.rule_id = primary_coupon.rule_id AND primary_coupon.is_primary = 1
LEFT JOIN `regular_rules`
ON `main_table`.`rule_id` = `regular_rules`.`rule_id`
It looks great to me. However, I get the following error message:
SQLSTATE [42S22]: : 1054 "main_table.rule_id" "on"
, , , main_table.rule_id . , , , , , , -, .
, ( rule_coupons) ( regular_rules) .
: ... phpMyAdmin , . PHP script mysqli, . , (Magento). Magento, , ... , , .