Kelv
Kelv

Reputation: 49

SQL filter rows in table

I'm trying to select rows from a table with the exception of any rows containing 'NEW_' at the beginning. I think I have the logic correct but I am unsure of the syntax. Can anyone help me out?

 SELECT * 
FROM CUSTOMER e1
WHERE e1.cust_ref LIKE 'CUST_REF%'
  AND e1.cust_ref NOT IN (SELECT e2.cust_ref 
                       FROM CUSTOMER e2  
                       WHERE e1.cust_ref = 'NEW_' + e2.cust_ref);

Upvotes: 0

Views: 43

Answers (3)

Praveen
Praveen

Reputation: 9335

Here is SQL query for filter option

select * 
from sd_filter_element
WHERE 
cust_ref not like 'NEW_%';

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269563

If you just want cust refs that don't have "NEW_", why not just do this?

select c.*
from CUSTOMER c
WHERE c.cust_ref not like 'NEW_%' ;

Upvotes: 0

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

select * from CUSTOMER 
WHERE cust_ref  like 'CUST_REF%'
AND cust_ref not in 
(select cust_ref from sd_filter_element where cust_ref not like 'NEW_%');

You should use like to do this.

Upvotes: 1

Related Questions