这个检索用Sql语句怎么写?

holy_cyt 2001-11-01 06:14:47
表a包括字段:a1,a2,a3,a4 主键为(a1,a2,a3)
表b包括字段:b1,b2,b3 主键为(b1)
其中a3与b1为同一类型字段
现要根据给定的字符串string1,string2取得
a表中对应于a1=string1 and a2=string2的所有a3,a4
再跟据得到的a3在b表中取得对应于a3=b1的所有b2,b3
最后再DBGrid中显示a4,b2,b3

请问该过程如何用Sql语句实现?
...全文
119 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
holy_cyt 2001-11-02
  • 打赏
  • 举报
回复
对不起,这两天都没上网
thank you,sunssc
dephi 2001-11-01
  • 打赏
  • 举报
回复
jh
sunssc 2001-11-01
  • 打赏
  • 举报
回复
select t.a4,b.b2,b.b3
from (select a.a3,a.a4
from a
where a.a1=string1 and a.a2=string2) as t,b
where t.a3=b.b1
holy_cyt 2001-11-01
  • 打赏
  • 举报
回复
去outer也一样
smhjh 2001-11-01
  • 打赏
  • 举报
回复
去你 out 试一试
holy_cyt 2001-11-01
  • 打赏
  • 举报
回复
要是把left outer join改为right outer join
则若要显示
a.a4 b.b2 b.b3
1 2 3
2 4 5
结果却显示
a.a4 b.b2 b.b3
1 2 3
1 2 3
2 4 5
2 4 5
holy_cyt 2001-11-01
  • 打赏
  • 举报
回复
比如,应该显示
a.a4 b.b2 b.b3
1 2 3
2 4 5
结果却显示
a.a4 b.b2 b.b3
1 2 3
2 4 5
1 2 3
2 4 5
linx88 2001-11-01
  • 打赏
  • 举报
回复
怎么样一个显示两遍法?
holy_cyt 2001-11-01
  • 打赏
  • 举报
回复
我又试了一下
把 where a.a3 in (select a.a3,a.a4 中的a.a4去掉,则可以执行
但是把我要显示的数据显示了两遍,怎么办?
holy_cyt 2001-11-01
  • 打赏
  • 举报
回复
1.我看了一下,首先是 where a.a3 in(select ...,
2.这样执行后,弹出错误信息:you have written a subquery that can return more
than one field without using the General SQL error.
EXISTS reserved words in the main query's FORM clause.Revise the select statement of the subquery to request only one field
是什么意思?
a_fee 2001-11-01
  • 打赏
  • 举报
回复
应该是where a.a3 in(select a.a3,a.a4
from a
where a.a1=string1 and a.a2=string2)
与linx88商榷。。。
linx88 2001-11-01
  • 打赏
  • 举报
回复
随手写的,错了别怪~~~
select a.a4,b.b2,b.b3
from a left outer join b on a.a3=b.b1
where b.b1 in(
select a.a3
from a
where a.a1=string1 and a.a2=string2)
linx88 2001-11-01
  • 打赏
  • 举报
回复
select a.a4,b.b2,b.b3
from a left outer join b on a.a3=b.b1
where b.b1 in(
select a.a3,a.a4
from a
where a.a1=string1 and a.a2=string2)

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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