2

I have a table which contains around 100 columns, and I need to select a row from the table but with only the field with not null value. for example, row 1 contains only 50 fields with not null value and 50 fields with null value. I need to select only the 50 fields with not null value.

I use mysql, symfony2, doctrine

Cordially

Pradeep
  • 105
  • 6
Majdi Taleb
  • 731
  • 3
  • 9
  • 26
  • possible duplicate of [MySQL SELECT only not null values](http://stackoverflow.com/questions/5285448/mysql-select-only-not-null-values) – Alex Sep 03 '15 at 14:44
  • 2
    you can't query different number of columns (fields). any mysql query will always return same number of columns! so if you request for 100 fields it will always return 100 fields irrespective of what you put in any variant of `WHERE` clause. Any filter or conditions affect only on number of records returned and values, but never changes number of columns returned. – Alex Sep 03 '15 at 14:47
  • I have a table that contains 100 columns. when I do this in Doctrine and execute: $entity = $em->getRepository('entityname')->find($id); the returned result is a single of course which contains combination of null and not null value. I'd like to filter the result to get only the not null value and put them into a variable and then use them in twig as DropDownList. – Majdi Taleb Sep 03 '15 at 15:44
  • dropdownlist of what? – Alex Sep 03 '15 at 15:46
  • The most important thing for me is to select only the not null fields , and after that, I'll put these values in a variable (array ) that I will use it in twig and put its values in dropdownlist – Majdi Taleb Sep 03 '15 at 15:51
  • reread my first comment. you can't get different number of returned fields. so if your request return 100 fields. the only way to filter is to loop through all 100 values and do something you need even if you need to create new array. Sorry you should read more on internet. Post your current query – Alex Sep 03 '15 at 16:11

1 Answers1

2

This question was answered in a different question on here. Please check out the link below.

MySQL SELECT only not null values

Community
  • 1
  • 1
  • 1
    This should be a comment. – Kmeixner Sep 03 '15 at 14:24
  • I ask if there are a method that can select only not null value without specifying all columns name, because 100 colums is too much – Majdi Taleb Sep 03 '15 at 14:41
  • I have a table that contains 100 columns. when I do this in Doctrine and execute: $entity = $em->getRepository('entityname')->find($id); the returned result is a single of course which contains combination of null and not null value. I'd like to filter the result to get only the not null value and put them into a variable and then use them in twig as DropDownList. – Majdi Taleb Sep 03 '15 at 15:44