0

i need to query a database and return fields for each row i query but skip the empty fields or NULL fields. I have researched a lot about what i want and i arrived at something close with the following url's

MySQL SELECT only not null values

https://chartio.com/resources/tutorials/how-to-select-records-with-no-null-values-in-mysql/

They both gave the same answers:

SELECT
  primary_author,
  published_date,
  title
FROM
  books
WHERE
  (
    primary_author IS NOT NULL
  AND
    published_date IS NOT NULL
  );

The problem is, doing it this way doesn't give me the result that i want because It skips the entire row. I still want to fetch fields from every row but i only want to skip empty fields in each row that is returned. Else i would have to use Php too loop through and skip NULL or empty values after running my query, which taxes the server. It is better if i can get MySQL to do it for me.

I want something like this SELECT * (except NULL) FROM table.

It is not standard SQL but i feel it explains my point. So please is it possible?

Ikechukwu
  • 1,135
  • 1
  • 13
  • 30

0 Answers0