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 02:04:48 #6
 surymani   Member Since: October 2008    Total Comments: 1 

RE: write a query to update third column such that
 
create table aa(name varchar(10), marks1 int, marks2 int, maxmarks int)

insert into aa values ('a',10,20,null)

insert into aa values ('b',20,25,null)

update a
set maxmarks= d.marks
from aa a, (select name, max(marks) as marks
                  from (select name,marks1 as marks from aa
                           union all
                           select name,marks2 as marks from aa) as c
                  group by name ) as d
where a.name=d.name
     

 

Back To Question