查询~~~~~~~~~~~~~~~~~~~

zhengweitao 2009-03-03 04:38:03
表1
id name
1 2
1 3
1 4
2 2
2 3
2 4
3 1

表2
id age
1 18
3 18

我想查出表1 查询条件 用表2的age列 查出表1(age = 18)

查询结果 表1
id name
1 2
1 3
1 3
1 4
3 1

记得有什么 内练 外联 的 我不会 还有什么多对一 一对多的
...全文
102 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
ysw830 2009-03-03
  • 打赏
  • 举报
回复
select id,name from table1 inner join tabel2 on tabel1.id=tabel2.id where tabel2.age=18
ysw830 2009-03-03
  • 打赏
  • 举报
回复
select id,name from table1 inner join tabel2 on tabel1.id=tabel2.id
hahanan1987 2009-03-03
  • 打赏
  • 举报
回复
select 表1.id as id,name
from 表1 left outer join
(select id,age
from 表2
where age='条件') as 表3
on 表1.id = 表3.id
zzxap 2009-03-03
  • 打赏
  • 举报
回复
结贴吧
zzxap 2009-03-03
  • 打赏
  • 举报
回复
[code=SQL]
SELECT * FROM 表1 where id in ( select id from 表2 where age ='18')
[/CODE]
huzi01245 2009-03-03
  • 打赏
  • 举报
回复
楼主要两个1,3,因此需要左连接left join
zhengweitao 2009-03-03
  • 打赏
  • 举报
回复
怎么我一发帖 你们就看不明白 为什么有的人能看明白????
林g 2009-03-03
  • 打赏
  • 举报
回复
不明白?
我姓区不姓区 2009-03-03
  • 打赏
  • 举报
回复

select 表1.* from 表1 inner join 表2 on 表1.id=表2.id and 表2.age=18

不知道是不是要这个效果
zhong2006 2009-03-03
  • 打赏
  • 举报
回复
需要翻译!
叶子 2009-03-03
  • 打赏
  • 举报
回复

declare @表1 table (id int,name int)
insert into @表1
select 1,2 union all
select 1,3 union all
select 1,4 union all
select 2,2 union all
select 2,3 union all
select 2,4 union all
select 3,1

select * from @表1
/*
id name
----------- -----------
1 2
1 3
1 4
2 2
2 3
2 4
3 1
*/

declare @表2 table (id int,age int)
insert into @表2
select 1,18 union all
select 3,18

select * from @表2
/*
id age
----------- -----------
1 18
3 18
*/

select a.* from @表1 a right join @表2 b on a.id=b.id

/*
id name
----------- -----------
1 2
1 3
1 4
3 1
*/
zjq0034 2009-03-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ojlovecd 的回复:]
谁来帮我翻译一下楼主的话
[/Quote]
说得太过分了,虽然我也没看懂……
叶子 2009-03-03
  • 打赏
  • 举报
回复

declare @表1 table (id int,name int)
insert into @表1
select 1,2 union all
select 1,3 union all
select 1,4 union all
select 2,2 union all
select 2,3 union all
select 2,4 union all
select 3,1

select * from @表1

declare @表2 table (id int,age int)
insert into @表2
select 1,18 union all
select 3,18

select * from @表2

select a.* from @表1 a right join @表2 b on a.id=b.id

qshurufa 2009-03-03
  • 打赏
  • 举报
回复
SELECT ID, NAME FROM Table1 WHERE ID=(SELECT ID FROM Table2 WHERE AGE=18)
我姓区不姓区 2009-03-03
  • 打赏
  • 举报
回复
谁来帮我翻译一下楼主的话
北京的雾霾天 2009-03-03
  • 打赏
  • 举报
回复
select a.id, a.name, b.age
from 表1 a
inner join 表2 b on a.id=b.id;
underwater 2009-03-03
  • 打赏
  • 举报
回复
一边看自己一边可以尝试

内联还好,外联老手都经常忘

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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