Home > Net >  UPDATE a field with SQL where another field is not empty
UPDATE a field with SQL where another field is not empty

Time:10-22

I want to auto update with PHP/SQL the last_modified datetime of an entry. The city vars I am binding could sometimes filled with a city and sometimes stay empty or mixed filled and empty.

How can I just apply a clause within the WHERE clause if city is NOT empty? The problem is, I have some entries with empty cities in the database, so if a binded var is empty it will also be updated.

I tried it with "city <> ''" but it isn't working properly and shows me more results that expected.

UPDATE result_page
SET last_modified = ?
WHERE city = ? OR city = ? OR city = ? OR city = ? AND city <> ''

CodePudding user response:

UPDATE result_page 
  SET last_modified = ? 
     WHERE city <> '' AND (city = ? OR city = ? OR city = ? OR city = ?) 
  • Related