且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将一个表复制到其他表,避免某些记录

更新时间:2022-12-11 23:25:54

简化你的SQL:



  INSERT   INTO  t2 
SELECT *
FROM t1
WHERE t1.Bus_name NOT LIKE ' 009%' AND t1.Bus_name LIKE ' 01% 跨度>


Hi,
I am trying to copy records of one table(t1) to other table(t2). Both have same fields but I have to exclude certain records while copying to t2.
here is my query but it is not working and when i do search I am still able to see the records

Query -

INSERT INTO t2
SELECT * FROM t1
where not exists (select * from t1 where (t1.Bus_name like '009%'; and t1.Bus_name like '01%'; ));

I still see records with business name starting with 009 and 01 in my new table t2.

Please help !!

Simplify your SQL to this:

INSERT INTO t2
SELECT *
FROM t1
WHERE t1.Bus_name NOT LIKE '009%' AND t1.Bus_name NOT LIKE '01%'