简体   繁体   English

在mysql中字段列表中的字段“ field”是不明确的

[英]Column 'field' in field list is ambiguous in mysql

INSERT INTO  users (phone, no_of_coupon) 
SELECT couponentries.phone, 1
FROM couponentries LEFT JOIN users ON couponentries.phone = 
users.phone
WHERE users.phone IS NULL
ON DUPLICATE KEY UPDATE users.no_of_coupon = users.no_of_coupon + 1;

I am trying to input date in the couponentries table and then it will automatically insert only the phone numbers into users table. 我正在尝试在couponentries表中输入日期,然后它将仅将电话号码自动插入到users表中。 If there is a duplicate phone number, no_of_coupon will increment by 1. But when I executed this code in the phpmyadmin trigger trigger , it has an error below. 如果电话号码重复,则no_of_coupon会增加1。但是,当我在phpmyadmin Trigger 触发器中执行此代码时,下面有一个错误。 Could someone help me please? 有人可以帮我吗? Thanks 谢谢

Could not able to execute Column 'users.no_of_coupon' in field list is ambiguous 无法执行字段列表中的列“ users.no_of_coupon”不明确

You need to provide an alias to users table used in join clause 您需要为join子句中使用的users表提供别名

INSERT INTO  users (phone, no_of_coupon) 
SELECT c.phone, 1
FROM couponentries c 
LEFT JOIN users u ON c.phone = u.phone
WHERE u.phone IS NULL
ON DUPLICATE KEY UPDATE users.no_of_coupon = users.no_of_coupon + 1;

I guess you don't need the join part you can just use 我猜你不需要只可以使用的连接部分

INSERT INTO users (phone) 
SELECT c.phone
FROM couponentries c 
ON DUPLICATE KEY UPDATE no_of_coupon = no_of_coupon + 1;

Demo 演示版

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM