Home >Database >Mysql Tutorial >How to Select MySQL Columns with Non-Empty Values?
Selecting MySQL Columns with Non-Empty Values
In MySQL, selecting columns based on the presence of data can be achieved using various methods. Consider the task of selecting only rows where a specific column, like 'phone2', contains non-empty values.
To address this, one approach involves comparing the value of 'phone2' with an empty string. The following query demonstrates this:
select phone, phone2 from jewishyellow.users where phone like '813%' and phone2<>''
By comparing 'phone2' with an empty string, the query retrieves rows where 'phone2' has any non-empty value. It's important to note that NULL values are treated as false in this comparison.
This approach provides a straightforward method for selecting rows with non-empty columns, ensuring that the retrieved results meet the desired criteria.
The above is the detailed content of How to Select MySQL Columns with Non-Empty Values?. For more information, please follow other related articles on the PHP Chinese website!