Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip blank data in MySQL?

Tags:

null

mysql

I wanted to skip blank data in MySQL.

My sample query is:

SELECT id, name, date from sample where name IS NOT NULL;

Sample table:

id     name         date
1                  24-04-2012
2      abc         23-04-2012

Now if I fire above query, it gives me both record but I want to skip data which is stored as blank i.e. There is nothing(not even NULL)?

So how can I skip 1st record? What should be my query?

So how to skip blank data in MySQL?

Please guide me.

like image 801
Prat Avatar asked Apr 24 '12 13:04

Prat


People also ask

How do you skip NULL values?

You can ignore null fields at the class level by using @JsonInclude(Include. NON_NULL) to only include non-null fields, thus excluding any attribute whose value is null. You can also use the same annotation at the field level to instruct Jackson to ignore that field while converting Java object to json if it's null.

What is the use of <> in MySQL?

The symbol <> in MySQL is same as not equal to operator (!=). Both gives the result in boolean or tinyint(1). If the condition becomes true, then the result will be 1 otherwise 0. Case 1 − Using !=

How do you select non blank values in SQL?

Select non-empty column values using NOT IS NULL and TRIM() function. The syntax is as follows. SELECT * FROM yourTableName WHERE yourColumnName IS NOT NULL AND TRIM(yourColumnName) <> ' '; You can select non-empty value as well as whitespace from column using the same TRIM() function.


1 Answers

You can eliminate both NULL and empty/blank strings from your results using the following:

 where name IS NOT NULL AND name <> ''
                        ^^^^^^^^^^^^^^ add this

Demo: http://www.sqlfiddle.com/#!2/1155a/6

Edit: As pointed out in the comments, trim is not even necessary.

like image 196
mellamokb Avatar answered Oct 13 '22 02:10

mellamokb