If I have a table T with 4 rows & 2 columns A & B. A has
values 1,2,3,4. and B has 10,20,30,40. Write an Update SQL
query which can Swap the values of A & B for all records.
(Do not use a sub-query)

Answers were Sorted based on User's Feedback



If I have a table T with 4 rows & 2 columns A & B. A has values 1,2,3,4. and B has 10,20,30..

Answer / bunty

UPDATE T
SET A = B,B=A;

I am surprized but above query will fetch the desired
result.

Cheers,
Bunty

Is This Answer Correct ?    30 Yes 1 No

If I have a table T with 4 rows & 2 columns A & B. A has values 1,2,3,4. and B has 10,20,30..

Answer / avi007

select A as "B",B AS "A" from T;

Is This Answer Correct ?    1 Yes 2 No

If I have a table T with 4 rows & 2 columns A & B. A has values 1,2,3,4. and B has 10,20,30..

Answer / lova raju allumalla

update T set A=B,B=A where A in (select A from T);

Is This Answer Correct ?    1 Yes 2 No

If I have a table T with 4 rows & 2 columns A & B. A has values 1,2,3,4. and B has 10,20,30..

Answer / amit

UPDATE T
SET A = B, ENVDOR_NUMBERB = A

Is This Answer Correct ?    1 Yes 4 No

If I have a table T with 4 rows & 2 columns A & B. A has values 1,2,3,4. and B has 10,20,30..

Answer / preeti mishra

update T
set A:=A+B,
B:=A-B,
A:=A-B;

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More SQL PLSQL Interview Questions

Explain what is a subquery ?

0 Answers  


how to rename an existing table in mysql? : Sql dba

0 Answers  


What is the use of a view in sql?

0 Answers  


how to remove records from table? no name 1 a 2 b 1 a 2 b 3 c

8 Answers   Oracle,


What is nosql db?

0 Answers  






Does truncate release storage space?

0 Answers  


Can we rollback delete command?

0 Answers  


Hi All, I am new to both this blog and technology. I was able to see a response for one of the questions on triggers as below. I would like to know why are we using " if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then" instead, can't we use " if sysdate = 'sunday' then". I can understand the use of "rtrim", but dont know y v r using to_char. I have seen this in many cases but did not get a convincible explaination. Please help me with this and do excuse if this question sounds silly. Thanks in advance...... create or replace trigger trg_sun before insert on <table name> begin if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then raise_application_error(-20345,'no transaction in sunday'); end if; end trg_sun;

2 Answers  


Does sap use sql?

0 Answers  


How to get list of all tables from a database?

0 Answers  


what are ddl statements in mysql? : Sql dba

0 Answers  


Why is theta join required?

0 Answers  


Categories