sql的小问题。

camel_luo 2002-05-17 10:58:35
我用的是ADO+ACCESS。有数据库A的表1和数据库B的表2,它们有一个相同的字段name,我想用sql语句选出表1字段name有的而在表2中没有的那些记录,怎么写?谢谢,在线等待,马上结贴
...全文
30 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
camel_luo 2002-05-17
  • 打赏
  • 举报
回复
不管怎么,谢谢liuhelin(鹤林)
liuhelin 2002-05-17
  • 打赏
  • 举报
回复
你想要没有的比较麻烦,我只知道如何做子母表,给你个思路
先加一个adoquery1连接到数据库a的表1,
adoquery1.sql:='select name from table1';
并加一个数据源
datasource1.dateset:=adoquery1;
再加一个adoquery2连接到数据库b的表2
adoquery2.datasource:=datasource1;
adoquery2.sql:='select * from employee
where deptid=:name';
注意:name是adoquery1.fieldbyname('name')的值,所以一次就一个值。
这样的异构查询没问题,但是你要的是not in query1,我也没什么办法
只好复制到一个数据库中再select了
liuhelin 2002-05-17
  • 打赏
  • 举报
回复
up
wait
camel_luo 2002-05-17
  • 打赏
  • 举报
回复
with ADOQuery1 do
begin
SQL.Clear;
SQL.Add('select * from 场地.场地表 where 场地代码 not in (select 场地名 from ReportMake.场地表)');
ExecSQL;
first;
while not ADOQuery1.Eof do
begin
StringGrid1.Cells[0,row_num]:=cddaima;
StringGrid1.Cells[1,row_num]:='今天没有报帐';
row_num:=row_num+1;
StringGrid1.RowCount:=StringGrid1.RowCount+1;
next;
end;
end;

结果是执行时报错:ADOQuery1:Cannot perform this operation on a closed dataset
camel_luo 2002-05-17
  • 打赏
  • 举报
回复
liuhelin(鹤林) 能具体讲讲吗?
linyin 2002-05-17
  • 打赏
  • 举报
回复
不用吧!delphi是能做到的呀
linyin 2002-05-17
  • 打赏
  • 举报
回复
select 表1.name from 表1 where name not in (select 表2.name from 表2)
liuhelin 2002-05-17
  • 打赏
  • 举报
回复
这是异构的查询,delphi能做到但以上的都不行,需要用query的参数能够实现
sdldp 2002-05-17
  • 打赏
  • 举报
回复
select * from A.table_1 where name not in (select name from B.table_2)
票票飞扬 2002-05-17
  • 打赏
  • 举报
回复
select * from table_1 where name not in (select name from table_2)
hammer_shi 2002-05-17
  • 打赏
  • 举报
回复
select * from A.table_1 where name in (select name from B.table_2)
fyje 2002-05-17
  • 打赏
  • 举报
回复
select * from tblA where name=null(select name from tblB)

5,930

社区成员

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

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