I have a table like so:
Code: Select all
CREATE TABLE images (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
file_id SMALLINT UNSIGNED NOT NULL,
img1 VARCHAR(250) DEFAULT NULL,
img2 VARCHAR(250) DEFAULT NULL,
img3 VARCHAR(250) DEFAULT NULL,
img4 VARCHAR(250) DEFAULT NULL,
img5 VARCHAR(250) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE (file_id)
);SELECT {look at img1, img2, img3, img4 and img5 and return the 'count' of how many of these columns are NOT NULL} WHERE file_id=5
In other words, I want the query to look at those 5 image columns and count how many of them have values (not null). Does anyone know how this can be done? I'm completely stumped, not even sure if that is possible. Thanks for any help and guidance. Take care.