Home >Database >Mysql Tutorial >How to Select MySQL Columns with Non-Empty Values?

How to Select MySQL Columns with Non-Empty Values?

Barbara Streisand
Barbara StreisandOriginal
2024-12-21 20:46:47971browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn