我运行下面的脚本。 UserDetails.User#中没有记录AccountDetails.User#的记录。但结果显示,UserDetails中的每个用户#在脚本中指定的每个AccountDetails.account#中有3次。 如果SQL连接语句中没有匹配项,它是否应该返回任何内容?
DataType和样本值的背景很少:
UserDetails.user#
datatype = varchar(520)
values in (1,0)
AccountDetails.user#
datatype = varchar(11)
values in (22054414,28581057,26178648)
我跑的脚本:
SELECT a.account# , a.userNum , u.userNum, u.Name
FROM AccountDetails a
JOIN UserDetails u ON a.userNum = u.userNum
WHERE a.account# IN (87173000,11900008,79000082)
示例结果:
account#, a.userNum, u.userNum , u.Name
87173000, 22054414, 1, Joe Blow
87173000, 28581057, 1, John Smith
11900008, 22054414, 1, Joe Blow
11900008, 28581057, 1, John Smith
79000082, 22054414, 1, Joe Blow
79000082, 28581057, 1, John Smith
答案 0 :(得分:0)
SELECT a.account , a.user , u.Name FROM AccountDetails a JOIN UserDetails u ON (a.user = u.user) WHERE a.account IN (87173000,11900008,79000082) GROUP BY a.user