求购一sql语句,在线等待~~~解决就结帐

HndyLiu 2003-12-03 04:02:09
table1:
code names
001 aaa
002 bbb
……

table2:
code title
001 AAAA
002 AAAA
003 AAAA
0004 BBBB
……

根据输入的参数与table2的title比较得到table2的code
select code from table2 where title='AAAA'

现在,我需要根据上述语句得到的code到table1匹配:
我应该怎么样得到table1里的name值???
select code,name from table1 where code ???
...全文
47 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2003-12-03
  • 打赏
  • 举报
回复
select * from table1 a left join table2 b on b.code = a.code where b.title = 'AAAA'
来晚了!!
DeltaCat 2003-12-03
  • 打赏
  • 举报
回复
select a.code,a.names from table1 a,table2 b where b.title='AAAA' and a.code=b.code and a.flag = b.flag
HndyLiu 2003-12-03
  • 打赏
  • 举报
回复
看来,我用monkeys的方法好了

谢谢大家的帮助
verge 2003-12-03
  • 打赏
  • 举报
回复
select a.name a.code from table1 a left join table2 b on b.code = a.code where b.title = 'AAAA'
DeltaCat 2003-12-03
  • 打赏
  • 举报
回复
select a.code,a.names from table1 a,table2 b where b.title='AAAA' and a.code=b.code
shleo 2003-12-03
  • 打赏
  • 举报
回复
把两个表连接起来
大家都对~
vivisogood 2003-12-03
  • 打赏
  • 举报
回复
用视图啊!
HndyLiu 2003-12-03
  • 打赏
  • 举报
回复
Triumph(夜雨) ( ) 的结果是记录增加了几倍

monkeys(study.net) ( ) 的比他的稍微少一点

ygghost(刘华强) ( )的更多了

不过效果倒是实现了,但是记录多了很多
我在table1和table2里都加了一个字段:flag
我查询的条件加上了:table1.flag = table2.flag

请问该怎么写??
yzllfcn 2003-12-03
  • 打赏
  • 举报
回复
select a.names from table1 as a,table2 as b
where b.title='AAAA' and b.code=a.code
ygghost 2003-12-03
  • 打赏
  • 举报
回复

select a.names,b.* from table1 as a inner join table2 as b on a.code=b.code
monkeys 2003-12-03
  • 打赏
  • 举报
回复
试试看,希望对你有帮助:
select code,name from table1 where code in (select code from table2 where title='AAAA')
Triumph 2003-12-03
  • 打赏
  • 举报
回复
select table1.names from table1,table2 where table1.code=table2.code and table2.title='AAAA'

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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