MySQL query excluding empty LINES [duplicate]

0

I have to make a query (which will be taken to a PHP application) in the table below. I would like to query so that the rows that do not contain prices (that is, they are null) in columns 'gnbr' to 'sprd' are not selected. I do not want to delete the lines that are blank (because if I need to register prices in them, I would need to retype the cod, prod, fab, qtd and carac.) I just want to query so that the result set to be sent to php does not receive these lines. the number of lines is variable (there will always be a new stuff) so I can not do 'WHERE cod = xxxx;' for example. Can someone give a north, at least ?? grateful.

    
asked by anonymous 11.10.2016 / 02:18

2 answers

2

Good afternoon. You need to indicate the condition in WHERE. It can be done as follows:

SELECT * FROM produtos WHERE gnbr IS NOT NULL AND sprd IS NOT NULL.

You need to manually add each element with "AND {field_name} IS NOT NULL".

    
11.10.2016 / 22:59
1

If you want to check if the line has at least NULL , you can add all the numeric columns in question and delete the rows where that sum is NULL :

WHERE (gnbr + vnse + ... + sprd) IS NOT NULL

Or:

WHERE NOT ISNULL(gnbr + vnse + ... + sprd) 

I do not know about the efficiency of these variations. The sum of the columns certainly has a "weight" on the query, I suggest analyzing a% of% of it.

If you want to delete only rows where all columns are EXPLAIN , you can use this:

WHERE COALESCE(gnbr, vnse, ... , sprd) IS NOT NULL

NULL works by establishing a fallbacks chain . The result will only be COALESCE if all columns are null.

    
11.10.2016 / 23:07