javamysqlsap-commerce-cloudhybris-data-hubflexible-search

Flexible Search Query Condition (if else?)


I have a question, I have to make a query where I have to show in a column the value "yes" or "no" depending on whether or not there is an image on a product. I have to join the product table this is safe but how can I tell in the query if the "image presence" field is not empty write "no" otherwise "yes". I hope I have explained. Thank you all.


Solution

  • You could use the CASE statement, here is a quick example from w3schools

    SELECT CustomerName, City, Country
    FROM Customers
    ORDER BY
    (CASE
        WHEN City IS NULL THEN Country
        ELSE City
    END);
    

    Something to note, is that depending on the DBMS you're using, the syntax may (or may not) be different

    https://www.w3schools.com/sql/sql_case.asp