Reputation: 347
I have two tables: gal and TCPD_personel_COPY. I want to insert in TCPD_PERSONEL_COPY, that users which are in gal and not exists yet in TCPD_PERSONEL_COPY whit condition gal.country='Germany'
. But I have also the conditions :
(gal.name not like '07_%'
gal.name not like 'TR_%'
gal.name not like 'ST_%'
gal.name not like 'KB_%'
gal.name not like 'HS_%'
gal.name is not null)
to this condition I don't have the country specified.
I try to use the next code but it doesn't work proper:
How I can do this code to work proper?
Upvotes: 0
Views: 43
Reputation: 865
Change this part:
where (gal.name not like '07_%' or
gal.name not like 'TR_%' or
gal.name not like 'ST_%' or
gal.name not like 'KB_%' or
gal.name not like 'HS_%' or
gal.name is not null)
These should be ANDs not ORs.
If the name is not null NO MATTER WHAT THE VALUE IS it's going to be selected because the ORs mean ANY ONE OF THOSE CONDITIONS mush be met for it to be true.
Upvotes: 1
Reputation: 63752
You need to use and
, not or
.
You are looking for all the data, except for the items that don't start with a given phrase. So you want the ones where name doesn't start with 07_
, nor TR_
, nor ST_
... But you're using not like
, so what you need to ask is "Name doesn't start with 07_, and it doesn't start with TR_, and it doesn't start with ST_, ...".
Using or
instead of and
means that you always get everything, since if something starts with 07_
, it can't start with TR_
as well, that's simply impossible - and you select all for which at least one of those conditions fit - since the conditions are "mutually inclusive", true
is the only possible result.
Upvotes: 1