Say I have a table like this:
Table name: Test
col1 | col2 | col3 | col4
--------------------------
a | 0 | 0 | 1
Is it possible to retrieve the row, and just the column that is not zero, without having to list each column separately?
Is there a simple way to just select the row that has a value of 1? only 1 column will have a integer value of 1 on each row.
I am trying to get the column name of this one row that is not zero. The columns in this table will grow, so I dont want to have to list each column name in my sql statement. Im using SQLite.
relational databases are intended to do operations in rows, not in columns.. so columns operations are very inefficient. Maybe you are using wrong approach to your problem. consider this: suppose that you found a way to solve your situation, what will happen if more than one “1” is present? what if no “1” is present?
then i suppose you want also the column name that has “1” value, so where do you manage to store it in result?
I Strongly suggest you to store that info in another table, so you can quickly achieve what you want.