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

How to Select Rows with Non-Empty Columns in MySQL?

DDD
Release: 2024-12-22 10:58:12
Original
685 people have browsed it

How to Select Rows with Non-Empty Columns in MySQL?

Choosing Non-Empty Columns in MySQL: Selecting Data with Existing Values

In MySQL, you can filter rows based on the existence of values in specific columns. To select only rows where a certain column is not empty, a simple yet effective solution involves comparing the column's value with an empty string. This approach is particularly useful when working with columns that may contain both actual values and NULL values.

To apply this technique, you can modify the provided query as follows:

select phone, phone2 
from jewishyellow.users 
where phone like '813%' 
and phone2<>''
Copy after login

By using the <>'' operator, you compare the phone2 column with an empty string, ensuring that only rows with non-empty phone2 values are retrieved. It's worth noting that NULL values are interpreted as false in this context. Therefore, this query effectively selects rows where phone starts with '813' and phone2 contains any value, excluding NULL values.

The above is the detailed content of How to Select Rows with Non-Empty Columns in MySQL?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template