GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL

 Print  |  
Question:  write a query to update third column such that

Answer: There is a table having the following columns :-
student id marks1 marks2 maxmarks
1 10 20 20
2 25 30 30
3 30 10 30
4 35 25 35
5 20 40 40


write a query to update column maxmarks such that maxmarks column contains
whatever be the greater value among marks1 and marks2 columns ( as shown in table ).


October 10, 2008 10:56:06 #7
 sureshkumar.mtech   Member Since: May 2008    Total Comments: 6 

RE: write a query to update third column such that
 

table have a data:
-----------------

SQL> select * from sa;

NAME             SALA     SALARY MAX_SALARY
---------- ---------- ---------- ----------
sathish          1000       2000
saro             2500       1250
mathu            7000       5000
karthi           1700        900

Result:
--------

update sa set max_salary =
(
select  x.Max_salary1 from
(
select name,max(sal) Max_Salary1 from
  (
  select name,sala sal from sa
  union all
  select name,salary sal from sa)
group by name)x where sa.name = x.name
);


SQL> select * from sa;

NAME             SALA     SALARY MAX_SALARY
---------- ---------- ---------- ----------
sathish          1000       2000       2000
saro             2500       1250       2500
mathu            7000       5000       7000
karthi           1700        900       1700

     

 

Back To Question