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<>''
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!