I am using sql query to fetch rows from table. I want to select the rows only with distinct values and if there is no value entered for some row, that row should not be there.
SELECT DISTINCT meta_value FROM `wp_postmeta` WHERE meta_key = "aaa";
This is the query I am using, I am getting the distinct rows by this query but also getting the blank row.
SELECT column_names FROM table_name WHERE column_name IS NOT NULL; Query: SELECT * FROM Student WHERE Name IS NOT NULL AND Department IS NOT NULL AND Roll_No IS NOT NULL; To exclude the null values from all the columns we used AND operator.
Use the relational operators != or <> to exclude rows in a WHERE clause. The following query assumes that you are selecting from an ANSI-compliant database; the statements specify the owner or login name of the creator of the customer table.
In SQL, the DISTINCT clause doesn't ignore NULL values. So when using the DISTINCT clause in your SQL statement, your result set will include NULL as a distinct value.
Simple solution:
SELECT DISTINCT meta_value FROM `wp_postmeta` WHERE meta_key = "aaa" AND meta_value != "";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With