
vb SQL多表联合查询问题(Access数据库表)
2个回答
展开全部
联合查询不是你那么用的,联合查询是用于字段的联合,也就是会横向扩展表。
例如A表中会有人物id,姓名,年龄等,而b表中会有每个人每次考试的成绩,也就是成绩id,成绩分数,人物id。
这时如果要查询什么人(姓名)得了多少分,就需要用联合查询了。也就是将成绩表横向扩展出一栏姓名出来。
你这种情况应该把数据放在一个表里比较好点。
如果实在不希望改数据库,那么有这么两种办法:
1.子查询:就像badkano
回答的。不过那个new_table
名称要你自己改的。不能原样不动。这个表你自己根据那几个表的结构建,你不是说那几个表完全一样吗。
2.在程序代码中用循环语句分几次查询,最后把查询结果合到一块。
3.用语句建立一个临时表,将那些表的内容都查询到临时表里面。
例如A表中会有人物id,姓名,年龄等,而b表中会有每个人每次考试的成绩,也就是成绩id,成绩分数,人物id。
这时如果要查询什么人(姓名)得了多少分,就需要用联合查询了。也就是将成绩表横向扩展出一栏姓名出来。
你这种情况应该把数据放在一个表里比较好点。
如果实在不希望改数据库,那么有这么两种办法:
1.子查询:就像badkano
回答的。不过那个new_table
名称要你自己改的。不能原样不动。这个表你自己根据那几个表的结构建,你不是说那几个表完全一样吗。
2.在程序代码中用循环语句分几次查询,最后把查询结果合到一块。
3.用语句建立一个临时表,将那些表的内容都查询到临时表里面。
展开全部
Adodc1.RecordSource
=
"select
new_table.编号,new_table.地址,new_table.名称,new_table.其它
from
(select
*
from
a
union
all
select
*
from
b
union
all
select
*
from
c
union
all
select
*
from
d
union
all
select
*
from
e)
as
new_table
名称
Like
"
&
"'"
&
text1.text
&
"'"
----补充---
new_table不是新建的表,只是给那括号里的查询起一个别名
要不可以改成
Adodc1.RecordSource
=
"select
new_table.编号,new_table.地址,new_table.名称,new_table.其它
from
(select
*
from
a
union
all
select
*
from
b
union
all
select
*
from
c
union
all
select
*
from
d
union
all
select
*
from
e)
as
new_table
where
名称
Like
"
&
"'"
&
text1.text
&
"'"
---补充---
少写了个where
=
"select
new_table.编号,new_table.地址,new_table.名称,new_table.其它
from
(select
*
from
a
union
all
select
*
from
b
union
all
select
*
from
c
union
all
select
*
from
d
union
all
select
*
from
e)
as
new_table
名称
Like
"
&
"'"
&
text1.text
&
"'"
----补充---
new_table不是新建的表,只是给那括号里的查询起一个别名
要不可以改成
Adodc1.RecordSource
=
"select
new_table.编号,new_table.地址,new_table.名称,new_table.其它
from
(select
*
from
a
union
all
select
*
from
b
union
all
select
*
from
c
union
all
select
*
from
d
union
all
select
*
from
e)
as
new_table
where
名称
Like
"
&
"'"
&
text1.text
&
"'"
---补充---
少写了个where
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询