简体   繁体   English

SQL Select和UPDATE,其中有多列,应选择一行

[英]SQL Select and UPDATE where there are multiple columns and should choose one line

In SQL server is it possible to insert data where there are different usernames and I have to chose a particular username and under that I have to input the answer column as true for that username only. 在SQL Server中,可以在存在不同用户名的地方插入数据,而我必须选择一个特定的用户名,并且在此之下,我必须仅将答案列输入为该用户名的true。

This is the query I tried - 这是我尝试的查询-

$sql = "UPDATE table SET Answer = Truee FROM (SELECT * FROM table WHERE Username='$username') WHERE Answer = 0";

This is shown as an error in my PHP page. 这在我的PHP页面中显示为错误。

You can't use a FROM in an UPDATE . 您不能在UPDATE使用FROM You shouldn't need to do the separate select. 您不需要进行单独的选择。

$sql = "UPDATE table SET Answer = True WHERE Username='$username' AND  Answer = 0";

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

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