我是Sql的新手。我有两张桌子
table_A (student_id, last_name, email, schoolA, ...)
table_B (student_id, last_name, email, schoolB, ...)
在table_A中,有些student_id为Null或'(空)。
从table_B中选择student_id插入table_A' student_id colm
当只匹配last_name和email时,同样当A.student_id为Null或。时 空。
这就是我的想法
INSERT INTO table_A (student_id)
SELECT student_id
From table_B
WHERE table_A.last_name = table_B.last_name AND table_A.email = table_B.email
AND table_A.student_id ='' OR table_A.student_id = NULL
我知道我写的sql没有任何意义。我只是想得到一个简单的例子或一些想法。
谢谢!
答案 0 :(得分:0)
这听起来更像是public async Task <Lead> BuildLeadFromRequest(object request)
{
var req = request as WebApplicationRequest;
if (req == null)
throw new Exception(); //TODO: Something better than throwing an exception
}
语句,而不是UPDATE
。
INSERT
请注意,您将student_id与UPDATE A
SET A.student_id = B.student_id
FROM table_A A
INNER JOIN table_B B
ON A.last_name = B.last_name
AND A.email = B.email
WHERE (A.student_id ='' OR A.student_id IS NULL)
进行比较,而不是IS NULL
。括号也很重要。
答案 1 :(得分:0)
无论如何试试这个:
INSERT INTO table_A (STUDENT_ID)
SELECT B.student_id
From table_B AS B, TABLE_A AS A
WHERE (A.last_name = B.last_name AND A.email = B.email )
OR A.STUDENT_ID ='' OR A.STUDENT_ID IS NULL