简体   繁体   中英

Regarding mysql where clause with empty string

My query

SELECT order_id, order_item_id, product_id, date_due, ship_via 
    FROM order_shipment 
    WHERE (product_id LIKE 'PP80403396-502%%' AND ship_via != '');

OR

SELECT order_id, order_item_id, product_id, date_due, ship_via 
    FROM order_shipment 
    WHERE (product_id LIKE 'PP80403396-502%%' AND trim(ship_via) != '');

does not give me any results.

My expectation would be to display to display the results where ship_via field is NULL or is not empty.

NULL is not empty string and not not empty string. And the result of comparison is neither true, nor false, it's NULL . You should use COALESCE to test for NULL or empty. Or OR .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM