05-05-2015 02:31 AM
Is this possible to run a query from already written query like
select distinct salary from (select user_id, sum(salary) from emp where month =3 group by user_id) ;
this is an example so consider we are having 10 different sum of salary ...but i want to figure that out from select * from select query ....
Thanks for reverting back ..
05-05-2015 04:41 AM
Yes, you can do nested queries.
If you want to continue work on a query that is already definied, save it into a table by using create table ... as select ...
05-05-2015 04:42 AM
Yes, you can do that no problem, its called a subquery when another one is nestled in brackets. I would however wonder why you are doing it like that, there are times to use subqueries, however from what you have said and posted, I don't think this is one of them. Perhaps post some test data and required output. Just from what you have posted, assuming it is differing months then:
select user_id, sum(salary) from emp group by month,user_id
rather than several queries. Also note that distinct salary may return more than one row from your query, so how will handle that?
05-06-2015 12:35 AM
Yes RW9@ & KurtBremser... i agree there are multiple ways but couldn't bring them that time so used that..
actually i used earlier select a,b from (select id ,cat from T 1 where some condition) aliasname....as i forgot to put this alias name so it makes me to put question here on discussion portal ...but thanks for the effrort you guys put ..i appreciate it .thanks..