我想做一个较复杂的查询:
query.sql.add('select * from t_Departmwnt where DepartmentID=(');
query.sql.add('select ParentID from t_Department)');
执行后的结果不对,请问怎样写才对

解决方案 »

  1.   

    先用工具调试好sql。
    =后一般只能返回单一值。
      

  2.   

    毫无关联的查询,你的查询和'select * from t_Departmwnt‘没有分别;
     说出你的确切需求,也许我能明白些。
      

  3.   

    query.sql.add('select * from t_Department where DepartmentID=(');
    query.sql.add('select ParentID from t_Department where Name=:PName)');
    我的t_Department表中有字段为DepartmentID,ParentID,Name
    我想查上Name等于一个名称时,表中DepartmentID等于他的ParentID的数据集!
      

  4.   

    select * from t_Departmwnt where DepartmentID=(select ParentID from t_Department)
    这种sql语法肯定是错误的,正确的表达应该是select * from t_Departmwnt where DepartmentID in 
    (select ParentID from t_Department)
      

  5.   

    也可以这样写,列出所有 t_Departmwnt 中字段:sqlStr:='select A.x1,A.x2...,A.x3 from t_Departmwnt A,t_Department B where A.DepartmentID=B.ParentID';query.sql.add(sqlStr);
      

  6.   

    query.sql.add('select * from t_Department where DepartmentID in(');
    query.sql.add('select ParentID from t_Department where Name=:PName)');