我正在尝试使用phpmyadmin中的MySQL查询交叉检查两个表中存在的行,然后,如果在两个表中找到userID
,则插入他们的userID
和用户名进入另一张桌子。这是我的代码:
INSERT INTO userswithoutmeetings
SELECT user.userID
IF('user.userID'='meeting.userID');
我一直受到这个错误的困扰:
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'IF('user.userID'='meeting.userID')' at line 3
我尝试过的其他语句已经有效但未将值存入表中。
答案 0 :(得分:1)
像
这样的东西INSERT INTO userswithoutmeetings(userId,userName)
SELECT DISTINCT a.userId, a.userName
FROM table1 a
INNER JOIN table2 b ON (a.userId = b.userId)