Search code examples
oracleoracle11goracle-sqldeveloper

Update select statement result in a column conditioned by another column (Oracle SQL)


I'm trying to write a Select query in Oracle SQL that will return first_name column as empty if last_name column is empty(Regarless what's in the first_name column value). For the first row "John" should be return as empty since he has no last_name I don't want to update the table, I just want a Select query that return empty first_name if last_name is empty. Thanks in advance!!!

enter image description here

enter image description here THIS SHOULD BE THE OUTCOME.


Solution

  • You can use CASE expression:

    SELECT customer_id,
           CASE
           WHEN last_name IS NULL
           THEN NULL
           ELSE first_name
           END AS first_name.
           last_name.
           age,
           country
    FROM   table_name