我仍然无法正确创建我的sql语法。

"SELECT DISTINCT p.id, p.sub_menu_id, p.sub_menu_name, m.category_id, m.image_id, p.sub_menu_price, p.status, i.file_url, m.default_menu_id, p.restaurant_id, m.id
               FROM sub_sub_menu AS p
               INNER JOIN menu AS m ON m.id = p.sub_menu_id
               INNER JOIN icon AS i ON i.id = m.image_id
               WHERE p.restaurant_id = '" . (int) $_SESSION['uid'] . "' ";


有我的代码,但是我想做类似m.id = p.sub_menu_id不正确的事情,请使用此m.default_menu_id = p.sub_menu_id

更新资料

"SELECT DISTINCT p.id, p.sub_menu_id, p.sub_menu_name, m.category_id, m.image_id, p.sub_menu_price, p.status, i.file_url, m.default_menu_id, p.restaurant_id, m.id
               FROM sub_sub_menu AS p
               INNER JOIN menu AS m ON m.id = p.sub_menu_id
                                    OR m.default_menu_id = p.sub_menu_id
               INNER JOIN icon AS i ON i.id = m.image_id
               WHERE p.restaurant_id = '" . (int) $_SESSION['uid'] . "' ";


现在,从m.default_menu_id = p.sub_menu_id中选择(显示)了两次行。

谢谢你的帮助!

最佳答案

INNER JOIN menu AS m
       ON m.id = p.sub_menu_id
       OR m.default_menu_id = p.sub_menu_id

关于mysql - sql语法中的第二个条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20924548/

10-11 17:34