Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select columns from a table which have non null values?

I have a table containing hundreds of columns many of which are null, and I would like have my select statement so that only those columns containing a value are returned. It would help me analyze data better. Something like:

Select (non null columns) from tablename;

I want to select all columns which have at least one non-null value.

Can this be done?

like image 534
Walker Avatar asked Feb 08 '10 06:02

Walker


People also ask

How do you select a record with no NULL values?

To display records without NULL in a column, use the operator IS NOT NULL. You only need the name of the column (or an expression) and the operator IS NOT NULL (in our example, the price IS NOT NULL ). Put this condition in the WHERE clause (in our example, WHERE price IS NOT NULL ), which filters rows.

How do I get columns with NULL values?

You can use df. isnull(). sum() . It shows all columns and the total NaNs of each feature.

WHERE columns are not null SQL?

By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.


1 Answers

select column_name from user_tab_columns where table_name='Table_name' and num_nulls=0; 

Here is simple code to get non null columns..

like image 51
raghu gs Avatar answered Oct 17 '22 05:10

raghu gs