ACCESS数据库多表查询

ACCESS数据库多表查询,第1张

Select aID,bName,bName from

TableA a inner join TableB b

Where TableAID=TableBID

提供两种方案:

方案一:

用SQL中的UNION来做,

即将sql = "SELECT FROM a1 where xh='"&number&"'" 改为

sql = "SELECT FROM a1 where xh='"&number&"'union (SELECT FROM a2 where xh='"&number&"')"

方案二:

若表的数目太多,建议改用循环来做,因为此处表名是有规律的,即a加上一个序号,因此可以考虑将序号由循环变量来表示。如:

for i=1 to max

sql= "SELECT FROM a" & trim(str(i)) & " where xh='"&number&"'"

next

以上想法并未测试,仅供参考。

1、首先在使用的电脑上,添加想要查询数据库的服务和监听,通过Oracle客户端管理工具中的Net Manager来完成。

2、创建两个数据库的连接---DBLink,可以通过指令完成,也可以通过图形界面完成。

3、在Oracle管理工具中开启一个新的SQL windows窗口,测试 *** 作我们连接的异地Oracle数据库。

4、编写一个查询语句来测试,这里做一个select *** 作。

5、最后运行,如下图可以看到查询结果。

mysql支持多个库中不同表的关联查询,你可以随便链接一个数据库

然后,sql语句为:

select from db1table1 left join db2table2 on db1table1id = db2table2id

只要用数据库名加上""就能调用相应数据库的数据表了

数据库名表名

扩展资料

mysql查询语句

1、查询一张表:     select from 表名;

2、查询指定字段:select 字段1,字段2,字段3from 表名;

3、where条件查询:select 字段1,字段2,字段3 frome 表名 where 条件表达式;

例:select from t_studect where id=1;

  select from t_student where age>22

4、带in关键字查询:select 字段1,字段2 frome 表名 where 字段 [not]in(元素1,元素2);

例:select from t_student where age in (21,23);     

   select from t_student where age not in (21,23);

5、带between and的范围查询:select 字段1,字段2 frome 表名 where 字段 [not]between 取值1 and 取值2;

例:select frome t_student where age between 21 and 29;

     select frome t_student where age not between 21 and 29;

首先要检查你的表与表之间是不是有约束(主外键约束),如果存在,才可以像 上面这位朋友的方式进行连接,一般连接有左连接、右连接、内连接,下面给你举例:\x0d\\x0d\----做笛卡尔积\x0d\select sid,sname,scid,scsname,scscore from infom s ,score sc\x0d\\x0d\------内连接 写法一\x0d\select sid,sname,scid,scsname,scscore \x0d\from infom s ,score sc inner join score sc\x0d\on sid= scid ------内连接的条件\x0d\------on sid scid --------是全集 - 交集\x0d\------where scscore>80 \x0d\\x0d\------内连接 方法二\x0d\select sid,sname,scid,scsname,scscore \x0d\from infom s ,score sc\x0d\where sid= scid \x0d\\x0d\------\x0d\\x0d\-------------------------------------------------------外连接 左连接\x0d\--------------左表数据完全显示,右表中相同的数据显示,不同数据null\x0d\select Studentname,scorescore\x0d\from Student left join score -----------------先写的为左表\x0d\on Studentid=score id -----------------连接条件\x0d\\x0d\-------------------------------------------------------外连接 右连接\x0d\--------------右表数据完全显示,左表中相同的数据显示,不同数据显示null\x0d\select Studentname,scorescore \x0d\from Student right join score \x0d\on Studentid=score id \x0d\\x0d\-------------------------------------------------------全连接 full join\x0d\-------------------------------------------------------左、右表的数据完全显示,相同的数据显示一次\x0d\select Studentname,scorescore \x0d\from Student full join score \x0d\on Studentid=score id \x0d\\x0d\-------------------------------------------------------交叉联接\x0d\------------------------------------------交叉联接得到的是两表联接所有的数据组合\x0d\------------------------------------------(A表的数据记录 B 表的数据记录)\x0d\-------------------------------------------方式一\x0d\select Student,score from Student,score \x0d\-------------------------------------------方式二\x0d\select score ,Student from Student \x0d\cross join score \x0d\\x0d\-----------------------------------------------------多表联接\x0d\--------------------------------------要求查出张三 C#的考试成绩,涉及student,score,subject三个表\x0d\---------方式一:\x0d\select studentname,subjectsname ,score score\x0d\from Student\x0d\inner join score\x0d\on studentid= scoreid\x0d\inner join subject \x0d\on scoreid=subjectid\x0d\where Studentname='张三and subjectsname='C#'\x0d\\x0d\---------方式二:等值联接\x0d\select studentname,subjectsname ,score score\x0d\from Student,score ,subject\x0d\where StudentDBid=scoreid and score id=subjectid\x0d\ and Studentname='张三and subjectsname='C#'

以上就是关于ACCESS数据库多表查询全部的内容,包括:ACCESS数据库多表查询、数据库多表查询、oracle怎样查询两个表格中的全部数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9760737.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存