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

How to Select MySQL Columns with Non-Empty Values?

Barbara Streisand
Release: 2024-12-21 20:46:47
Original
1012 people have browsed it

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<>''
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template