In EMP table, for those emp whose Hiredate is same, update
their sal by "sal+500" or else for others keep the sal as it
is, how to do it by SQL query
Answers were Sorted based on User's Feedback
Answer / sanjaygupta1981
UPDATE emp
SET sal=sal+500
WHERE hiredate IN (SELECT hiredate
FROM employees
HAVING COUNT(*)>1
GROUP BY hiredate)
The above query will update the records of all those employees
whose hiredate is same.
| Is This Answer Correct ? | 17 Yes | 5 No |
Hi Sanjay,
the query u posted is a bit wrong,1st u have to do group by
n then having clause comes n not vise versa. so the final
query will be as below:
UPDATE emp
SET sal=sal+500
WHERE hiredate IN (SELECT hiredate
FROM employees
GROUP BY hiredate
HAVING COUNT(hiredate)>1
)
Hi Srinu,
It doesn't matter whether u write count(*) or
count(hiredate),the answer will always the same but its
better to give count(hiredate) only as it is easier to
understand.
| Is This Answer Correct ? | 6 Yes | 2 No |
Hi Srinu,
you check the query once again..Query is not wrong..
UPDATE emp
SET sal=sal+500
WHERE hiredate IN (SELECT hiredate
FROM emp
HAVING COUNT(*)>1
GROUP BY hiredate
it'll give the same result whether we write count(*) or
count(hiredate)..
But I agree but its better to give count(hiredate)instead of
COUNT(*)...coz it is easier to understand.
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / guest
update emp a set a.sal=a.sal+500 where a.hiredate in(select
max(b.hiredate) from emp b group by b.hiredate having
count(b.hiredate)>1);
or
update emp a set a.sal=a.sal+500 where a.hiredate=(select
max(b.hiredate) from emp b where a.hiredate=b.hiredate group
by b.hiredate having count(b.hiredate)>1);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sukanta
update emp a set a.sal=a.sal+500 where a.hiredate in(select
max(b.hiredate) from emp b group by b.hiredate having
count(b.hiredate)>1);
or
update emp a set a.sal=a.sal+500 where a.hiredate=(select
max(b.hiredate) from emp b where a.hiredate=b.hiredate group
by b.hiredate having count(b.hiredate)>1);
above is Posted By
Sukanta
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / srinivas
Hi suraj no need to put first group by and then having
clause
we can give any order it will work
please check and let me know
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / sbvp
update emp set sal=sal+500
or
alter table emp modify sal=sal+500
| Is This Answer Correct ? | 1 Yes | 28 No |
Suppose we are using a Dynamic Lookup in a Mapping and the commit Interval set for the tgt is 10000. Then how does the data get committed in the lookup if there were only 100 roows read from the src and the dynamic lookup dint have the 100th row in it?
suppose we are using dynamic lookup cache and in lookup condition the record is succeeded but in target it is failed due to some reasons then what happened in the cache ?
How many dimensions are there in informatica?
Can a joiner be used in a mapplet.
how to run workflow in unix?
5 Answers Colgate, HP, Tech Mahindra,
If we use sorted ports in aggregator transformation and somehow records are not in order by format so what will happen,session fails or it succeeded with incorrect data?
In informatics server which files are created during the session rums?
How to display session logs based upon particular dates. If I want to display session logs for 1 week from a particular date how can I do it without using unix.
what are the limitations for bulk loading in informatica for all kind of databases and transformations?
How to load the name of the current processing flat file along with the data into the target using informatica mapping?
WHAT IS FACT TABLES?
Can yoU use the maping parameters or variables created in one maping into another maping?