So I don't know how to exclude the null columns and get other column data. Like when I try to get data of id = 1, I want to exclude null columns(name) and get other columns(id, email, and address) data. Similarly, when I try to data of id = 3, I want to exclude columns(address) and get other columns(id, email, and name) data only.
Asked
Active
Viewed 44 times
-1
-
So you want a 3 column result for id = 1 and 4 column result for id = 2? – Salman A Jul 14 '21 at 11:58
-
Does this answer your question? [Exclude lines results that have NULL value in any field?](https://stackoverflow.com/questions/11795340/exclude-lines-results-that-have-null-value-in-any-field). Or [MySQL SELECT only not null values](https://stackoverflow.com/questions/5285448/mysql-select-only-not-null-values) – astentx Jul 14 '21 at 12:05
-
3In general, one query will return a result set with a *fixed* "shape" - the number of columns, their names and types. Are you sure trying to solve this at the *sql* level is the right thing to do? I'd suggest you leave such a *presentation* concern to your presentation/reporting layer. – Damien_The_Unbeliever Jul 14 '21 at 13:35
1 Answers
0
You can not exclude columns when only a few values are null on a dataset like yours. But try :
SELECT ISNULL(name, '') as name FROM TABLE_NAME

Chaturanga
- 78
- 5