Home » SQL & PL/SQL » SQL & PL/SQL » Use Alias in Query (Oracle 9i)
Use Alias in Query [message #327373] Mon, 16 June 2008 04:36 Go to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
Friends,

I have this query

select empno,(sal*1000)+(select pf from pf_table tab1 where empno=tab2.empno) Salary from emp tab2

in this query i want to use the Salary alias column in another column like this

Salary-dedu Deducted_Salary

Any way to use like this? otherwise again i have to write the calculate query+100.

please share with me if you have any ideas..

Advance Thanks
Mano




Re: Use Alias in Query [message #327375 is a reply to message #327373] Mon, 16 June 2008 04:41 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Any way to use like this?

No unless you push it in a subquery and use it in an outer one.

Regards
Michel
Re: Use Alias in Query [message #327377 is a reply to message #327373] Mon, 16 June 2008 04:42 Go to previous messageGo to next message
rajatratewal
Messages: 507
Registered: March 2008
Location: INDIA
Senior Member
You can use with clause to write this query.and then you can use this column.

You can't access it directly.
Re: Use Alias in Query [message #327387 is a reply to message #327373] Mon, 16 June 2008 04:58 Go to previous messageGo to next message
saikumar_mudigonda
Messages: 23
Registered: June 2008
Location: hyderabad
Junior Member
here is the sample data, may be this helps.

SQL> select * from emp;

     EMPNO        SAL
---------- ----------
         1       2000
         2       3400
         3       4500

SQL> select * from pf;

     EMPNO         PF
---------- ----------
         1        200
         2        340
         3        450

SQL> select * from dedu;

     EMPNO       DEDU
---------- ----------
         1      10000
         2      30000
         3      50000

SQL> 


SQL> select b.empno, a.salary-b.dedu from (select empno,(sal*1000)+(select pf from pf tab1 where empno = 
no = tab2.empno) salary from emp tab2) a,dedu b
  3  where a.empno = b.empno
  4  /

     EMPNO A.SALARY-B.DEDU
---------- ---------------
         1         1990200
         2         3370340
         3         4450450 /
Re: Use Alias in Query [message #327448 is a reply to message #327373] Mon, 16 June 2008 07:57 Go to previous messageGo to next message
jaganerp@gmail.com
Messages: 63
Registered: April 2008
Member
u have to use like this np
Re: Use Alias in Query [message #327449 is a reply to message #327448] Mon, 16 June 2008 08:02 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
jaganerp@gmail.com wrote on Mon, 16 June 2008 14:57
u have to use like this np

What does this mean?
Please post in english.

Regards
Michel

Previous Topic: PLS-00049: bad bind variable -- please help
Next Topic: Ref cursor
Goto Forum:
  


Current Time: Sat Dec 10 03:24:47 CST 2016

Total time taken to generate the page: 0.11620 seconds