Check for data in column [closed]

5

How can I check if there is data inside a column in a table?

I want to do a check and if there is data in the column it displays a div .

I know mysql_num_rows to add up the data that was fetched, but I wanted to know if it has any way to check data within a column.

    
asked by anonymous 24.10.2015 / 03:51

1 answer

-1

If it is to check only one column, make a SELECT by counting the results, using as an attribute, if the column is not empty ( IS NOT NULL ), in the WHERE clause. So you will know if there are any results. In the following example this is how to validate if there are records for the column, to make your select should put all the items that are necessary for the query that was doing, in order to get the correct result.

SELECT count(COLUNA) as TOTAL FROM TABLEA WHERE COLUNA IS NOT NULL;

In this case you get the result of the select with the alias " TOTAL " and if it is different from 0 , then display the results, coming from another SELECT preferably.

Doing this way will reduce consumption of MYSQL , considering that otherwise it will return a whole table row, so at the end of the column being empty it ignores it. Although using IS NOT NULL and placing the same column in mysql will not give an error, however, in this case it will be necessary to use mysql_num_rows and this would consume more resources than doing count in a field.     

30.10.2015 / 18:33