SQL UPDATE using CASE WHEN with PHP variable as argument

[quote=“andygout, post:1, topic:114817, full:true”]Saving the variable in a NULL state stores it as an empty string rather than an actual NULL value, which causes problems later when filtering results by IS NULL/IS NOT NULL (which I’ll need to do when using SELECT commands with CASE WHEN to call mat_nm for those without an article and mat_alph for those with). I don’t want to save a mat_alph value for titles without an article as this will apply to a huge amount, repeating the mat_nm value and wasting memory.[/quote]by the way, this is well thought out and quite sensible

since you appreciate brevity, you can use COALESCE instead of your CASE WHEN

there’s also a way to do it with pure SQL (i.e. no stored extra column) – MySQL: Proper sorting of a column - #22 by casbboy