delete 表1 where exists(select 列1 from 表2)

解决方案 »

  1.   

    delete 表1 where 列1 in(select 列1 from 表2)
      

  2.   

    楼主别给我分,我问问题呢?create database db_test
    gocreate table t_MaxTable
    (
    t_No tinyint not null identity(1,1),
    t_Title varchar(50) not null default '此处为大表主题'
    constraint PK_tTi primary key
    )
    goinsert into t_MaxTable (t_Title) values ('')
    insert into t_MaxTable (t_Title) values ('1此处为主题')
    insert into t_MaxTable (t_Title) values ('2此处为主题')
    insert into t_MaxTable (t_Title) values ('3此处为主题')
    insert into t_MaxTable (t_Title) values ('4此处为主题')select * from t_MinTablecreate table t_MinTable
    (
    t_No tinyint not null identity(3,1),
    t_Title varchar(50) not null
    )
    goinsert into t_MInTable (t_Title) values ('asdsadasd')
    insert into t_MInTable (t_Title) values ('asdasdsadasd')
    insert into t_MInTable (t_Title) values ('asdasadsd')
    insert into t_MInTable (t_Title) values ('asasasdsadasd')
    go
    --delete 表1 where 列1 in(select 列1 from 表2)delete t_MaxTable where t_No in (select t_No  from t_MinTable )select * from t_MaxTable 
    godrop table t_MaxTable
    drop table t_MinTable
    gouse database master
    godrop database db_test-------------------------------
    我刚学SQL,我想问一下,(select t_No  from t_MinTable ),select 不是表内查询吗?怎么可以用这样的语句呢?怎么可以用Select 表1 from 表2的字段呢?
      

  3.   

    delete 表1 where 列1 in (select 列1 from 表2)