2

I have table with 3 columns:

enter image description here

I want to get all records where type like '%' and is_connect like 'N', Including rows where type IS NULL or contains a string.

My query:

SELECT * 
FROM OFFER 
WHERE TYPE LIKE '%' 
AND IS_CONNECT LIKE 'N';

I got the rows where type is NOT NULL, but how can I get all rows, even when the type IS NULL?

1

4 Answers 4

1

If you want to get all or the rows where there is either a value or no value, simply exclude the field from your where clause:

SELECT * FROM OFFER WHERE IS_CONNECT = 'N';
Sign up to request clarification or add additional context in comments.

Comments

1

Try this.

Where N is you first alphabet. 
SELECT * FROM OFFER 
WHERE TYPE is null 
AND IS_CONNECT LIKE 'N%';

Where N is the last alphabet in your type. 
SELECT * FROM OFFER 
WHERE TYPE is null 
AND IS_CONNECT LIKE '%N';

__ BCG14

Comments

1

just remove the like clause if you want all the entries for type :

SELECT * FROM OFFER WHERE (TYPE LIKE '%'  or TYPE is NULL) AND IS_CONNECT = 'N';

2 Comments

This is probably a better solution than mine..I would probably go with this... Since you are really not doing anything special with a check like TYPE LIKE '%'
i can't remov like clause , i need to filter table with type and is_connect columns
0

You were almost there..Just use an OR condition to include null check...Also, you didnt have a 'N%' after is_connect like

SELECT * FROM OFFER WHERE (TYPE LIKE '%'  or TYPE is NULL) AND IS_CONNECT LIKE 'N%'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.