0

i have a table that looks like this

students
----------
ID  | Name  | Class  | Pass
01  | Lisa  | 01     | 1D345
02  | Mike  | 03     | 22341
03  | Kim   | 03     | 
04  | Lance | 04     | 193CC

So I wanted to select those where Pass is not empty, and I've tried

SELECT * FROM students WHERE Pass IS NOT NULL;

which returned the same table where it should have fetched me this

students
----------
ID  | Name  | Class  | Pass
01  | Lisa  | 01     | 1D345
02  | Mike  | 03     | 22341
04  | Lance | 04     | 193CC

I've also tried

SELECT * FROM students WHERE Pass IS NOT '';

and

SELECT * FROM students WHERE Pass !='';

both returning #1064 error, so what is the statement I should be using the fetch the required table?

2
  • Tag your question with the database you are using. Commented Oct 11, 2018 at 11:33
  • As a rule both returning error isn't much help, unless you actually include the error message. Commented Oct 11, 2018 at 11:46

1 Answer 1

1

Presumably, pass has a value other than NULL. This might work:

WHERE Pass <> ''

This is equivalent to your last option, which should work in most databases (most databases support both <> and != for inequality).

Or you might need to deal with spaces.

In MySQL, you can use a regular expression to be sure there is at least one alphanumeric character:

where pass regexp '[a-zA-Z0-9]'
Sign up to request clarification or add additional context in comments.

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.