以下两个sql语句执行结果为什么不同?
SELECT `main_table`.*, `sales_flat_order`.`order_uuid` FROM `sales_flat_order_grid` AS `main_table` LEFT JOIN `sales_flat_order` ON main_table.increment_id =sales_flat_order.increment_id WHERE (`status` = 'pending')
这个会报错Column 'status' in where clause is ambiguous
但SELECT `main_table`.*, `sales_flat_order`.`order_uuid` FROM `sales_flat_order_grid` AS `main_table` LEFT JOIN `sales_flat_order` ON main_table.increment_id = sales_flat_order.increment_id WHERE (billing_name LIKE '%e%')
这个能正常执行
status和billing_name都是sales_flat_order_grid的字段.
如果第一个语句中SELECT `main_table`.*, `sales_flat_order`.`order_uuid` FROM `sales_flat_order_grid` AS `main_table` LEFT JOIN `sales_flat_order` ON main_table.increment_id =sales_flat_order.increment_id WHERE (main_table.`status` = 'pending') 这样执行结果是对的.
我对第一句和第二句的执行结果表示疑问. 执行环境:mysql5.1
[解决办法]
因为sales_flat_order_grid表和sales_flat_order都有state列,如果没限定列名,mysql无法知道你用哪个表的这个列。就报错了这是编程规范,另外以后别在SQLServer问mysql的问题,不一定有人回复你的