求一句SQL

diudiuqqqq 2011-06-03 03:53:56
有A,B两张表
A表 B表
ID Type ID Name
1 2 1 aaa
2 2 2 bbb
3 1 3 ccc
4 1 4 ddd
5 1 5 eee
6 2 6 fff
7 1 7 ggg
8 2 8 hhh
9 2 9 iii

怎么写一句SQL把TYPE=2的ID和NAME都取出来?
...全文
110 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gaocy1 2011-06-05
  • 打赏
  • 举报
回复

select a.id,b.name
from a
join b on a.id = b.id
where a.type= 2
javatemptation 2011-06-05
  • 打赏
  • 举报
回复

select a.id,b.name
from a join b
on a.id = b.id and a.type = 2
chuanzhang5687 2011-06-04
  • 打赏
  • 举报
回复
select a.id,b.name from a inner join b on a.id = b.id and a.type= 2
cd731107 2011-06-04
  • 打赏
  • 举报
回复

select * from b
where id in (select id from A WHERE TYPE=2)
FlySQL 2011-06-04
  • 打赏
  • 举报
回复
if object_id('[A]') is not null drop table [A]
go
create table [A]([ID] int,[Type] int)
insert [A]
select 1,2 union all
select 2,2 union all
select 3,1 union all
select 4,1 union all
select 5,1 union all
select 6,2 union all
select 7,1 union all
select 8,2 union all
select 9,2
if object_id('[B]') is not null drop table [B]
go
create table [B]([ID] int,[Name] varchar(3))
insert [B]
select 1,'aaa' union all
select 2,'bbb' union all
select 3,'ccc' union all
select 4,'ddd' union all
select 5,'eee' union all
select 6,'fff' union all
select 7,'ggg' union all
select 8,'hhh' union all
select 9,'iii'

select a.id,b.name
from a
join b on a.id = b.id
where a.type= 2

/**
id name
----------- ----
1 aaa
2 bbb
6 fff
8 hhh
9 iii

(5 行受影响)
**/
lmlanren1234 2011-06-04
  • 打赏
  • 举报
回复
select A.ID,B.Name from A,B where A.ID=B.ID and A.ID=2
--小F-- 2011-06-03
  • 打赏
  • 举报
回复
select a.id,b.name from a inner join b on a.id = b.id and a.type= 2
深红龙骑兵 2011-06-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fredrichku 的回复:]
SQL code
select a.id,b.name
from a,b
where a.id = b.id
and a.type= 2
[/Quote]
+1
打一壶酱油 2011-06-03
  • 打赏
  • 举报
回复
select a.id,b.name
from a,b
where a.id = b.id
and a.type= 2
君_洛洛 2011-06-03
  • 打赏
  • 举报
回复
SELECT A.ID,B.NAME FROM A,B WHERE A.ID=B.ID AND A.TYPE=2
fredrichku 2011-06-03
  • 打赏
  • 举报
回复
select a.id,b.name
from a,b
where a.id = b.id
and a.type= 2

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧