简体   繁体   中英

SQL Join 2 tables together command

在此处输入图片说明

I have 2 tables as outlined above and I want to pass the current teams name into the Previous_Club column of the Player table. I have the logged in Team user's Team_ID set as a session variable so I am trying to query the Teams_Name using this and then passing it across to Player into the Previous_Club column. But it keeps erroring out. You can see the sql command below.

SqlCommand cmd2 = new SqlCommand("UPDATE Player SET Previous_Club = Team_Name FROM (SELECT Team_Name FROM TEAM WHERE Team_ID = @Team_ID)", con);

试试这个;

SqlCommand cmd2 = new SqlCommand("UPDATE Player SET Previous_Club = (SELECT Team_Name FROM TEAM WHERE Team_ID = @Team_ID)", con);

Query Error..Try this one

UPDATE Player 
SET Previous_Club = (SELECT Team_Name FROM TEAM WHERE Team_ID = @Team_ID)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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