Any easy way to select only columns with values?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Any easy way to select only columns with values?

Post by Ward »

I have a huge data table which stores CSV report data for users. A user can view his report, which currently selects all records tied to his userID. However, not all of the columns are even used, only around 5 or 10, depending on the CSV format which was uploaded. Is there any easy way to filter out the null columns in a select statement? The only other option is to do it through PHP, which will be more work.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Is this in a database or in a CSV text file? I am guessing a database. You can specify the columns that you want using the "SELECT col1,col2 FROM table" syntax. But you can't say to only provide data from non-Null columns. Besides, there is no data to retrieve so the Null columns should not increase the amount of data transfered much.
(#10850)
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

Its coming from a MySQL database. The data is put into a big 2-dimensional array, which is passed to a php datagrid control. I can only "hide" a column if the entire column has no values.
Post Reply