表1名字:table1 表2名字: table2
我在选择的是table1 中字段名为name 与表2 中字段名为test 相同的记录,请问这个select 语句怎么写?

解决方案 »

  1.   

    我是用CRecordset 派生类和这2个表一起绑定的,能不能用1个select 语句来查询2个表中符合条件的记录呢?
      

  2.   

    select * from table1 where name in (select test from table2)
      

  3.   

    我用 select * from md,md1 where md.name = md1.name 通过了,调试中发现连接并select 成功,可是程序调用 m_pset->GetFieldValue()的时候就出错了,错误信息:由于结果集是由一个连接条件生成的,无法执行定位请求。for(int j=0;j<nFieldCount;j++){
    m_pCommonRS->GetFieldValue(j, strValue);
    ctrlList.SetItemText(nCount, j, strValue);
    }
      

  4.   

    不过此时 m_pCommonRS中已经有内容了
      

  5.   

    我把代码改为:
    for(int j=0;j<nFieldCount;j++){
    //m_pCommonRS->GetFieldValue(j, strValue);
    ctrlList.SetItemText(nCount, j, m_pCommonRS->m_name);
    }
    后,可以得到结果集中字段为name 的内容,不过插入ctrlList 的没个field都是这个 name 的内容,有没有使用GetFieldValue 的办法呢?以上的 nFieldCount=m_pCommonRS->GetODBCFieldCount();
      

  6.   

    你的记录集不要和表绑定,就可以使用getfieldvalue
      

  7.   

    记录集不和表绑定的话,运行到 
    m_pCommonRS->Open(CRecordset::snapshot, strSQL);就报错了,错误信息:"SQLFetchScroll 和 SQLExtendedFetch 之前,没列被绑定"
      

  8.   

    select table1.field1 table2.field2 where table1.test=table2.test
      

  9.   

    select table1.name from table1,table2 where table1.name=table2.name