Table Photos-------
photo1 imagem1.jpg
photo2 imagem2.jpg
photo3 empty
photo4 empty
photo5 enpty
我有一个表,其中 5 列代表照片。 所以, 我想从表、所有列中选择 *...但如果其中一个或多个为空,我不想选择。这可能吗?
例如,如果我这样做
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
这是不可能的,因为如果其中一个为空...选择不会给出任何值。
有人知道另一种方法吗?
而且,我需要它,因为如果我想这样做: 问题是......当我使用 php 时,例如这个
if($project['photo5']!='' and $project['photo5']!=null){
(here i show the picture)
}
如果该行为空... php 将被忽略并显示错误图像
最佳答案
Concat()
如果任何一个值 concat 为 null ( mySQL DOCS ) 将返回 null,因为您只想显示不为 null 的记录 concat 在一起并检查是否为 null。
Select *
from table Photos
where concat(photo1,photo2,photo3,photo4,photo5) is not null
AND...如果您使用or
而不是AND
,并且可能使用not
,那么您的方法应该有效。我只是觉得上面的内容更容易阅读。
关于mysql - 从mysql中的非空列中选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35004429/