一个双表联查的sql语句或者有关问题
一个双表联查的sql语句或者问题
如题
我有 table A
id name
1 小张
2 小王
3 小李
table B
id key result
1 2 80
2 3 90
我现在 这样拼sql
select * from A a where a.id = (select b.key from B b where b.result = 90 )
我希望实现 搜索 B 表 满足result = 90 返回一个 key = 3;
然后 通过返回的 key = 3 再给 表A 作为搜索条件 找到 小李 。
以上我写的 sql 句子错误的 如何改 或者 用其他方式可以实现吗?
------解决思路----------------------
select * from B
inner join A
on B.key = A.id
where B.result = 90
------解决思路----------------------
select * from A a join B b on a.id=b.key where result = 90
(方法多种,不过你直接搜索result = 90的话有可能返回多项)
------解决思路----------------------
如题
我有 table A
id name
1 小张
2 小王
3 小李
table B
id key result
1 2 80
2 3 90
我现在 这样拼sql
select * from A a where a.id = (select b.key from B b where b.result = 90 )
我希望实现 搜索 B 表 满足result = 90 返回一个 key = 3;
然后 通过返回的 key = 3 再给 表A 作为搜索条件 找到 小李 。
以上我写的 sql 句子错误的 如何改 或者 用其他方式可以实现吗?
------解决思路----------------------
select * from B
inner join A
on B.key = A.id
where B.result = 90
------解决思路----------------------
select * from A a join B b on a.id=b.key where result = 90
(方法多种,不过你直接搜索result = 90的话有可能返回多项)
------解决思路----------------------
select A.name from A ,B
where A.id=B.key and B.result=90
declare @id int
set @id = (select B.[key] from B where B.result = 90)
select A.name from A where A.id=@id