现在有两个表 a和b 
a表结构:
account     user
管理          张三
经济          张三
经济          李四
.             .
.             .
.             .
b表结构:
user       pwd    department   
张三          1       行政室
李四          2       行政室
.           .        .
.           .        .
.           .        .
现在在一个combox中选择一个account,另一个combox就会显示可以使用这个account的所有user,请问这个代码该怎么写??? 

解决方案 »

  1.   

    select user from b where  user in (select user from a where account =所选择的account)
      

  2.   


    在ComboBox1的onChange事件中写入:procedure TForm1.ComboBox1Change(Sender: TObject);
    begin
       with ComboBox1 do begin
         if Text<>'' then begin
           Items.Clear;
           with adoquery2 do begin
            close;
            sql.Text:='select * from 表2 where user in(select user from 表1 where account='+QuotedStr(ComboBox1.Text)+')';
            open;
            while not eof do  begin
            ComboBox1.Items.Add(FieldValues['user']);
            next;
            end;
           end;
         end;
       end;
    end;
      

  3.   

    select user from a where account=条件.
      

  4.   

    1.无需用户详细信息只要用户名
    select user from a where account = 选择的account
    2.需要用户详细信息
    select b.* from a left join b on a.user = b.user 
    where account = 选择的account
      

  5.   

    谢谢各位的回答,但在我机子上通不过,最终这个测试通过:
      adoquery1.close;
      adoquery1.sql.clear;
      adoquery1.sql.add('select distinct fact from faccount');
      adoquery1.open;  adoquery1.first;
      combobox1.Clear;
      while not adoquery1.eof do
      begin
        combobox1.Items.add(adoquery1.fields[0].asstring);
        adoquery1.Next;
      end;
      combobox1.itemindex:=1;
    一会结贴了 !!!!