其实关键问题是这样的。
假如是一个字段,我们可以这样
select custom_name from t_custom where custom_name not in (select custom_name from t_trade)。
但是现在要求两个字段custom_name和product_name不能同时出现在t_trade中,这怎么办啊?

解决方案 »

  1.   

    select custom_name, product_name
    from t_custom c, t_product p
    where not exists (select 'x' from t_trade
                       where custom_name = c.custom_name
                         and product_name = p.product_name);
      

  2.   

    use mydb
    create table c(c_name char(10),col1 int)
    create table p(p_name char(10),col1 int)create table t(c_name char(10),p_name char(10)) insert into c(c_name) values('A')insert into c(c_name) values('B')
    insert into c(c_name) values('C')insert into t(c_name,p_name) values('A','1')insert into t(c_name,p_name) values('A','2')insert into t(c_name,p_name) values('B','2')
    insert into t(c_name,p_name) values('C','1')select distinct c_name,p_name from c,p where not exists (select c_name,p_name from t where c_name=c.c_name and p_name=p.p_name)
    上面是我的做法 c代表 t_custom表,p代表 t_product表,t代表 t_trade表我的结果是正确的
    c_name     p_name     
    ---------- ---------- 
    B          1         
    C          2         (2 row(s) affected)
      

  3.   

    select custom_name , product_name  from t_custom a,t_product b 
    where not exists(select * from t_trade c where a.custom_name = c.custom_name 
     and b.product_name  = c.product_name)