When using MySQL SELECT, can you change the value of the returned field based on other fields?
For example, if I have this choice:
SELECT city,state,country FROM table
Now, if the city is empty and the state is empty, I want the countryโs value to be empty too (regardless of whether the country matters or not).
Example table:
id | city | state | country ----------------------------- 1 | Here | There | MyCountry 2 | | | YourCountry
So, with the table above, I want the results for id = 1 to return here, there, MyCountry, but the results for id = 2 should be empty, empty, empty
thanks
EDIT: To clarify, the WHERE clause will not work, because I need a string returned even if the city and state are empty. A better example would be a SELECT id, city, state, country FROM my_table
jsherk
source share