I would like to select the entries in a mysql table where there are NULL values, to later do an update or a delete on them:
select * from table where q is NULL;
But I have a rather long list of them, in this case all with a given prefix called pf_
, and I want to select the entries where any of the columns is NULL. Can I do something like this?
select * from table where ANYISNULL(pf_q,pf_w,pf_e,pf_r,pf_t,pf_y,pf_u,pf_i,
pf_o,pf_p,pf_a,pf_s,pf_d,pf_f,pf_g,pf_h,
pf_j,pf_k,pf_l);
Any ideas how to do this other than having a very long query with lots of ORs?
You should do this:
select * from table where concat(pf_q,pf_w,pf_e,pf_r,pf_t,pf_y,pf_u,pf_i,
pf_o,pf_p,pf_a,pf_s,pf_d,pf_f,pf_g,pf_h,
pf_j,pf_k,pf_l) is null;
If any of the values is null, concat
will return null.
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