0

Table Photos-------

photo1  imagem1.jpg
photo2  imagem2.jpg
photo3  empty
photo4  empty
photo5  enpty

I have a table, with 5 columns who represents photos. So, I want to select * from table, all columns... but if one or more of them are empty, I don't want to select. is that possible?

For example, if I do this

Select * from table Photos where photo1 is not null, and photo2 is not null, and photo3 is not null and photo4 is not null and photo5 is not null 

that is not possible, because if one of them are empty... the select don't give any values.

anyone know another way?

and also, i need that because if I want to do this: the problem is.... when I use php for example this

if($project['photo5']!='' and $project['photo5']!=null){ 
(here i show the picture)
}

If the row is empty... php is ignored and show a error image

1
  • by empty do you mean the string 'empty' or do you mean NULL? and what's the table structure for photo table it appears to be 2 columns. If so what are the column names? If there are 5 columns called photo1 through photo5 then I have a different approach. based on the PHP and query there are 5 columns... Commented Jan 26, 2016 at 0:01

1 Answer 1

1

Concat() will return null if any one of the values concat is null (mySQL DOCS) Since you want to only show records where none are null concat together and check for not null.

Select * 
from table Photos 
where concat(photo1,photo2,photo3,photo4,photo5) is not null 

AND... your approach should work if you used or's instead of AND and possibly a not. I just find the above easier to read.

Sign up to request clarification or add additional context in comments.

3 Comments

if I have photo1, photo2, photo3 with content and photo4, photo5 empty i need that my select, only return the photo1, photo2, and photo3... not all another empty content
the problem is.... when I use php for example this if($project['photo5']!='' and $project['photo5']!=null){ (here i show the picture) } If the row is empty... php is ignored and show a error image
A select statement will always return the columns in the select. So if you want photo1-5 columns you will get 5 columns. The application (phP) will need to handle the absence of data for the column.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.