select count(*) as acount from a,b where a.f1=b.f2
Tadotable1对应a表的数据,Tadotable2对应b表的数据。 for i:=0 to ADOTable1.recordcount-1 do begin for j:=0 to ADOTable2.recordcount-1 do begin if ADOTable1.FieldByName('字段1').value=ADOTable2.FieldByName('字段2').value then ShowMessage('the same result'); else ADOTable2.next; end; ADOTable1.next; end; 这种方法将a表和b表中所有的数据都遍历了一遍,效率比较低。 建议用SQL语句: select * from a,b where a.field1=b.field2 如果返回值>0,则有相同的值;=0无相同值
支持jinjazz(近身剪(N-P攻略))
select count(*) as count from a where 字段1 in (select distinct 字段2 from 表2) 当返回的count大于0,则表明表2的字段2包含有表1的字段1的内容
select a.* from a where exist (select b.field2 from b where b.field2=a.field1)
select a.* from a where exist (select b.field2 from b where b.field2=a.field1) ——效率高select 1 from a where exist (select b.field2 from b where b.field2=a.field1) ——效率最高
for i:=0 to ADOTable1.recordcount-1 do
begin
for j:=0 to ADOTable2.recordcount-1 do
begin
if ADOTable1.FieldByName('字段1').value=ADOTable2.FieldByName('字段2').value then
ShowMessage('the same result');
else
ADOTable2.next;
end;
ADOTable1.next;
end;
这种方法将a表和b表中所有的数据都遍历了一遍,效率比较低。
建议用SQL语句:
select * from a,b where a.field1=b.field2
如果返回值>0,则有相同的值;=0无相同值
当返回的count大于0,则表明表2的字段2包含有表1的字段1的内容
——效率高select 1 from a where exist (select b.field2 from b where b.field2=a.field1)
——效率最高