How can I return a list of fields from a given table that contain any non-NULL data?
As en example, how could I query the example table below to only return the following three values as they contain something other than NULL.
- LO2_HiddenOrgID
- LO2_BranchOfOrgID
- LO2_ShortName

I’m looking to automate this as much as possible as I have a few thousand fields to inspect.
Also, I’m currently using SQLite while developing, but would happily accept any suggestions specific to SQLite, MySQL or PostgreSQL.
So your goal is to get the list of column names such that all of them have at least one non-NULL value in any of the rows, right? If so, see below…
You can’t parametrize names of columns in an SQL query, so you’ll need to build your SQL text dynamically, in the client language of your choosing. The algorithm would look like this:
column_namedynamically build the SQL text such as:SELECT column_name FROM YOUR_TABLE WHERE column_name IS NOT NULL LIMIT 1(see the MySQL LIMIT and PostgreSQL LIMIT).column_nameto the resulting list.The resulting list now contains columns with at least one non-NULL value.