表一  :  ID , webtel , hometel , type
表二  : ID , hometel , address
表三  :  ID , type , money
表四 :  ID , webte , hometel , address , type , money
表二和表一 用hometel关联
表三和表一用type 关联按下button1按纽表一表二表三的记录都会写入表四中以前是这样写的
insert into t4(ID , webte , hometel , address , type , money) 
select t1.id, t1.webte, t1.hometel, t2.address, t3.type, t3.money from t1,t2,t3 where t1.hometel = t2.hometel and t1.type = t3.type但上面那样的话所有的记录都生成到表四中了,现在想要改成选取DBGrid中的一行或多行有选择性的生成!这样怎么办?

解决方案 »

  1.   

    insert into t4(ID , webte , hometel , address , type , money) 
    select t1.id, t1.webte, t1.hometel, t2.address, t3.type, t3.money from t1,t2,t3 where t1.hometel = t2.hometel and t1.type = t3.type
    And  T1.Id= 選擇的條件或者
    insert into t4(ID , webte , hometel , address , type , money) 
    select t1.id, t1.webte, t1.hometel, t2.address, t3.type, t3.money from t1,t2,t3 where t1.hometel = t2.hometel and t1.type = t3.type
    And  T1.Id  in( 選擇的條件1,..)
      

  2.   

    insert into t4(ID , webte , hometel , address , type , money) 
    select a.id, a.webtel, a.hometel, b.address, c.type, c.money 
    from t1 a inner join t2 b on a.hometel = b.hometel 
    inner join t3 c on a.type = c.type
      

  3.   

    insert into t4(ID , webte , hometel , address , type , money) 
    select a.id, a.webtel, a.hometel, b.address, c.type, c.money 
    from t1 a 
    inner join t2 b 
    on a.hometel = b.hometel 
    left join t3 c on a.type = c.type
      

  4.   

    insert into t4(ID , webte , hometel , address , type , money) 
    select t1.id, t1.webte, t1.hometel, t2.address, t3.type, t3.money from t1,t2,t3 where t1.hometel = t2.hometel and t1.type = t3.type and t1.id=3
    就是直接在后面加条件就是了