Update the Status
Write an SQL query to interchange the values of the Status column (i.e, change all 'Employed' to 'Unemployed' and vice-versa) using an update statement.
ID is the Primary Key column for the Data table.
update Data set Status=( case when Status='Employed' then 'Unemployed' else 'Employed' End )
The given query is an SQL update statement that updates the ‘Status’ column of a table named "Data". The update is performed based on a conditional expression using a case statement.
The query starts by specifying the column to be updated, which is ‘Status’. It then uses a case statement to define the logic for the update.
The case statement evaluates the current value of the ‘Status’ column for each row. If the current value is 'Employed', it changes it to 'Unemployed'. Conversely, if the current value is anything other than 'Employed', it changes it to 'Employed'.
In other words, the query effectively toggles/interchanges the ‘Status’ values from 'Employed' to 'Unemployed' and vice-versa for all rows in the "Data" table.
No comments