Skip to main content

Posts

Showing posts from June, 2018

Swapping a column value of a table in a single query and not using temp table variable

There are some cases when your guess is right but for the lack of your confidence you have to leave some questions or facts.This doesn't mean that in such cases you need to deliver what you are guessing is good enough to show that you are confident rather not answering is sometime cuts better for those who respect themselves in such a way that "Talk less but always right".But If you are hungry for marks and there is no negative marking then proceed :) Q:Given a table of following structure and data you have to swap('M' to 'F' and 'F' to 'M') column value for column 'SEX' in a single query and you cannot use temp table. ID | SEX | Salary ------------------------ 1 M   45345.00 2 F   75345.00 3 M   64644.00 4 F   5555.00 5 M   34434.00 6 M   84434.00 The query is so simple UPDATE employee SET sex= CASE sex WHEN 'M' THEN 'F'  WHEN 'F' THEN 'M' END That's...