MY TABLES:
USERS_1: USERS_2:
+------------+---------+ +------------+---------+
| id |username | | username |claimedBy|
+------------+---------+ +------------+---------+
| 4 | pitiqu | | myUsername | NULL |<- this should become 4
+------------+---------+ +------------+---------+
MY SQL:(字面意思是MySQL)
UPDATE UL
SET UL.claimedBy = US.username
FROM USERS_1 as UL
INNER JOIN USERS_2 as US
ON US.id = 4
where UL.username="myUsername"
我可能很明显,我想将表2的'claim_by(用户名&#34; myUsername&#34;)设置为用户名&#34; pitiqu&#34;在表1中找到id = 4。
对不起所有&#34;用户名&#34;令人困惑。希望表格和SQL清除我的问题。
弹出的错误:
#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在US USERS_1附近使用UL INNER JOIN USERS_2作为US ON.US = 4,其中UL&#39;第3行
为什么会发生这种情况......有人吗?
编辑:请原谅我的语法不正确。我一直在尝试使用THIS示例,在编辑时我删除了SET。
答案 0 :(得分:3)
您可以使用这样的更新查询:
#include <stdio.h>
#include <stdlib.h>
int apare(char a, char s[]) //this function search a character in a string.
{
printf("merge");
int nr=strlen(s),i;
for(i=0; i<nr; i++)
{
if(a==s[i])
return 1;
}
return 0;
}
int main()
{
FILE * f=fopen("program in C.txt","r");
char c,s[10000]="abcedfghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ _-+=.,<>?!@#$%^&*()1234567890{}[];:'";//The characters I want to be printed
int a=1,k=0;//k is only used to printf "\n" when 1100 characters have been displayed on a line
while(a)
{
c=fgetc(f);//A char is read
if(c!=EOF)//If no error occurs than display the character if it is present in the string.
{
if(apare(c,s))
{
printf("%c",c);
k++;
}
}
else if(ferror) //If an error occurs than read the next char
c=fgetc(f);
else //If EOF than stop reading
a=0;
if(k==100)
{
k=0;
printf("\n");
}
}
return 0;
}
如果你想要一个连接,正确的语法是这样的,但是在这个特定的上下文中它没有多大意义,我建议你使用第一个查询:
update
USERS_2
set
claimedBy = (SELECT username FROM USERS_1 WHERE id=4)
where
username="myUsername"
答案 1 :(得分:2)
这是一个错误的语法。您应该使用像
这样的更新连接UPDATE UL u
JOIN USERS_2 US ON US.id = 4
SET u.claimedBy = US.username
where u.username='myUsername';
答案 2 :(得分:1)
您在FROM
查询中使用UPDATE
。这是完全错误的。
重写它的一种方法如下,使用子查询:
UPDATE USERS_2 set claimedBy = (SELECT id from USERS_1 where username = "pitiqu")
where username="myUsername";