1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Retreive two column values from a table

Discussion in 'SQL PL/SQL' started by gokul1242, Jun 6, 2012.

  1. gokul1242

    gokul1242 Active Member

    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    55
    Hi i want to retrieve two column values from one table and store the values as a single column value in another table...How to go with it???
     
  2. kiran.marla

    kiran.marla Forum Genius

    Messages:
    403
    Likes Received:
    52
    Trophy Points:
    505
    Location:
    Khammam
    Share your script here what had you did upto now.
     
  3. Bharat

    Bharat Community Moderator Forum Guru

    Messages:
    1,747
    Likes Received:
    147
    Trophy Points:
    1,805
    Location:
    Vijayawada, India
    Hi gokul,

    You can use concatenation operator to do that.

    Code (Text):


    Query: - select ename||' '||empno from emp;

    Output: -

    ENAME||' '||EMPNO
    ----------------
    KING   7839
    BLAKE  7698
    CLARK  7782
    JONES  7566
    SCOTT  7788
    FORD   7902
    SMITH  7369
    ALLEN  7499
    WARD   7521
    MARTIN 7654
    BPO    7844
    ADAMS  7876
    JAMES  7900
    MILLER 7934

    Now you can insert the above concatenated result into one column of any table. Here I have inserted another record in same table using above query.

    Query: - insert into emp(empno,ename,deptno) values(1,(select ename||' '||empno from emp where empno=7499),10);
              1 row inserted

    Query: - select ename||' '||empno from emp;

    Output: -

    ENAME||' '||EMPNO
    ----------------
    KING   7839
    BLAKE  7698
    CLARK  7782
    JONES  7566
    SCOTT  7788
    FORD   7902
    SMITH  7369
    ALLEN  7499
    WARD   7521
    MARTIN 7654
    BPO    7844
    ADAMS  7876
    JAMES  7900
    MILLER 7934
    ALLEN  7499 1

    Here we are getting 1 at end of last record just because of we have inserted a record from 7499 empno into the emp table with empno as 1. So as of our query we get that at the end.