If inside Where mysql

Posted by Barno on Stack Overflow See other posts from Stack Overflow or by Barno
Published on 2013-10-24T09:46:36Z Indexed on 2013/10/24 9:54 UTC
Read the original article Hit count: 165

Filed under:

Can I do an if inside Where? or something that allows me to do the checks only if the field is not null (path=null)

SELECT  
IF(path IS NOT NULL, concat("/uploads/attachments/",path, "/thumbnails/" , nome), "/uploads/attachments/default/thumbnails/avatar.png") as avatar_mittente
FROM prof_foto  
WHERE profilo_id = 15 
 -- only if path != "/uploads/attachments/default/thumbnails/avatar.png"
AND foto_eliminata = 0 AND foto_profilo = 1

© Stack Overflow or respective owner

Related posts about mysql