MySQL: Selecting Columns with Non-Empty Values
In MySQL, you can select specific columns only if they contain non-empty values. This allows you to filter out any rows where those columns are null or empty.
Example Query
Consider the following query:
select phone, phone2 from jewishyellow.users where phone like '813%' and phone2
Here, the goal is to select rows where:
Solution
To select columns only where non-empty values exist, you can compare the value of the column with an empty string.
select phone, phone2 from jewishyellow.users where phone like '813%' and phone2<>''
Explanation
Note: Null values are interpreted as false in MySQL. This means that rows with phone2 set to null will not be included in the results.
The above is the detailed content of How to Select Only Columns with Non-Empty Values in MySQL?. For more information, please follow other related articles on the PHP Chinese website!