Creating table using joins in subquery

can we create a table by using joins in subquery??
like this
create table emp as select * from employees e,departments d
where d.department_id=e.department_id
can we ??

What happens when you try it?
It worked for me. See below:
drop table test_table;
create table test_table as
select e.employee_id, e.first_name || ' ' || e.last_name ename, e.email, e.salary, d.department_name
  from employees e
  join departments d
    on (e.department_id = d.department_id)
where e.salary = 10000;
select *
  from test_Table;
EMPLOYEE_ID ENAME                                          EMAIL                       SALARY DEPARTMENT_NAME             
        150 Peter Tucker                                   PTUCKER                      10000 Sales                         
        156 Janette King                                   JKING                        10000 Sales                         
        169 Harrison Bloom                                 HBLOOM                       10000 Sales                         
        204 Hermann Baer                                   HBAER                        10000 Public Relations

Similar Messages

  • Logical error in creating tables using db link in solaris

    Hi,
    While creating table using the syntax create table newtab...as select * from tab@dblink .. I am facing a problem. The newtab table created is having a structure different (from datalength point of view of varchar2 and char datatypes) from the source. The data length is getting tripled i.e. if a column a is varchar2(20) in tab then it is becoming --- a varchar2(60) in newtab. This is happening in solaris environment when the two databases are in 2 different servers. Please let me know if there are any patches to resolve the problem.
    Thanks
    Arnab

    ORA-02019: connection description for remote database not foundHave you used this database link successfully for some other queries?
    The error posted seems to indicate that the DB Link is not functional at all. Has it worked for any other type of DML operation or is this the first time you ever tried to use the link?

  • How to create table using Procedure

    Hi,
    I want to create table using procedure .
    How to write procedure for the table creation?
    thanks in advance.

    Use dynamic sql or DBMS_UTILITY.EXEC_DDL_STATEMENT:
    SQL> desc tbl1
    ERROR:
    ORA-04043: object tbl1 does not exist
    SQL> begin
      2      execute immediate 'create table tbl1(x number)';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> desc tbl1
    Name                                      Null?    Type
    X                                                  NUMBER
    SQL> drop table tbl1
      2  /
    Table dropped.
    SQL> begin
      2      DBMS_UTILITY.EXEC_DDL_STATEMENT('create table tbl1(x number)');
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> desc tbl1
    Name                                      Null?    Type
    X                                                  NUMBER
    SQL>  SY.

  • Php deleting multiple table using join

    Hi
    I have three tables called  Users, Photolevel and  Photostatus.  In the Users table I have  an activekey colunm which is 1 or 0. When its 1 the user is not active when 0 the user is active.
    I would like to delete all unactive users from the Users database and from Photolevel , Photostatus.
    I have tried a table join with delete which is not working. can any one help.
    Photolevel.useid and Photostatus.useid should join and be delete to the Users table where activekey is 1.
    Heres the code.
    $dbclean=mysql_query("DELETE Users.id, Users.username, Users.surname, Users.email, Users.gender, Users.age, Users.password,
    Users.country, Users.city, Users.profilepic,
    Users.activecode, Users.activekey, Users.DOB, Users.Date, Photolevel.pid, Photolevel.useid,
    Photolevel.genre, Photolevel.start, Photolevel.end, Photostatus.stuid, Photostatus.useid, Photostatus.vgenre
    FROM Users, Photolevel, Photostatus WHERE
    Users.id = Photolevel.pid AND
    Photolevel.pid = Photostatus.stuid AND
    Users.activekey='1'");

    >$sqlgo = mysql_query("DELETE FROM Users.id, Users.activekey, Photolevel.pid, Photolevel.useid, Photolevel.genre, Photolevel.start, Photolevel.end FROM Photolevel INNER >JOIN
    >Users ON Photolevel.useid=Users.id and Users.activekey='1' and Photolevel.genre='Photolevel.genre'");
    Again, your syntax is incorrect. You do not specifiy a column list in a delete statement. If you want to delete rows from a table, you specify the table name after the DELETE operator. You can then qualify which rows to delete using joins in the FROM clause and/or conditions in the WHERE clause.
    $sqlgo = mysql_query("DELETE Photolevel FROM Photolevel INNER JOIN Users ON Photolevel.useid=Users.id and Users.activekey='1' ");
    This statement yields the same results as the one I provided earlier that used the subquery.
    >and Photolevel.genre='Photolevel.genre'");
    I'm not sure what you are trying here. A column always equals itself so that condition will always evaluate as TRUE.

  • Create Table using DBMS_SQL package and size not exceeding 64K

    I have a size contraint that my SQL size should not exceed 64K.
    Now I would appriciate if some one could tell me how to create a table using
    Dynamic sql along with usage of DBMS_SQL package.
    Brief Scenario: Users at my site are not given permission to create table.
    I need to write a procedure which the users could use to create a table .ALso my SQL size should not exceed 64K. Once this Procedure is created using DBMS_SQL package ,user should pass the table name to create a table.
    Thanks/

    "If a user doesn't have permission to create a table then how do you expect they will be able to do this"
    Well, it depends on what you want to do. I could write a stored proc that creates a table in my schema and give some other user execute privilege on it. They would then be able to create a able in my schema without any explicitly granted create table privilege.
    Similarly, assuming I have CREATE ANY TABLE granted directly to me, I could write a stroe proc that would create a table in another users schema. As long as they have quota on their default tablespace, they do not need CREATE TABLE privileges.
    SQL> CREATE USER a IDENTIFIED BY a
      2  DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
    User created.
    SQL> GRANT CREATE SESSION TO a;
    Grant succeeded.
    SQL> CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10));
    CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10))
    ERROR at line 1:
    ORA-01950: no privileges on tablespace 'USERS'So, give them quota on the tablespace and try again
    SQL> ALTER USER a QUOTA UNLIMITED ON users;
    User altered.
    SQL> CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10));
    Table created.Now lets see if it really belongs to a:
    SQL> connect a/a
    Connected.
    SQL> SELECT table_name FROM user_tables;
    TABLE_NAME
    T
    SQL> INSERT INTO t VALUES (1, 'One');
    1 row created.Yes, it definitely belongs to a. Just to show that ther is nothing up my sleeve:
    SQL> create table t1 (id NUMBER, descr VARCHAR2(10));
    create table t1 (id NUMBER, descr VARCHAR2(10))
    ERROR at line 1:
    ORA-01031: insufficient privilegesI can almost, but not quite, see a rationale for the second case if you want to enforce some sort of naming or location standards but the whole thing seems odd to me.
    Users cannot create tables, so lets give them a procedure to create tables?
    John

  • Create table using a dynamic SQL returns error.

    DBMS_UTILITY.exec_ddl_statement (
    'create table test_table as select column_names from table_name@dblink
    where condition' )
    i am using the above statement in a pl/sql procedure.
    It throws an error saying
    "Exact fetch returns more than requested no. of rows"
    can any one help me on this please!!!
    Very Urgent
    Thanks in Advance.
    Bala.

    Works for me. But the more important question would be the need to have this run within PL/SQL? Why do you want to do that? what is the requirement? can you not do this one time at SQL*Plus prompt and be done with it?
    SQL> drop table emp ;
    Table dropped.
    SQL>
    SQL>
    SQL> exec dbms_utility.exec_ddl_statement('create table emp as select * from [email protected] where deptno = 10') ;
    PL/SQL procedure successfully completed.
    SQL> select count(*) from emp ;
      COUNT(*)
             3
    1 row selected.
    SQL> select count(*) from [email protected] ;
      COUNT(*)
            14
    1 row selected.
    SQL> select count(*) from [email protected] where deptno = 10 ;
      COUNT(*)
             3
    1 row selected.
    SQL>Message was edited by:
    Kamal Kishore

  • How to create table using mysql in LabVIEW

    Hii
               I am using mysql database Toolkit for my project.  In that how to New create a table. Is there any possiblilites to create a table using query...can u send a sample prg ... and inform which toolkit Vi to use....  

    The SQL syntax for creating a table is:
    CREATE TABLE table_name
    column_name1 data_type,
    column_name2 data_type,
    column_name3 data_type,
    )The toolkit has a funciton called DB Tools Create Table. That would be the obvious function to use if you don't want to execute a SQL query to create the table. The tooklit comes with examples. Have you looked at them? There's one called Create Database Table that  would seem to be exactly what you are looking for.

  • Can't create table - using JDeveloper 11g (11.1.1.3.0)

    I am running a DDL to create a table:
    CREATE TABLE HORSE
    HORSE_NAME VARCHAR2(30) NOT NULL
    , PLACE VARCHAR2(20)
    , RACE_NAME VARCHAR2(30)
    , RACE_DATE DATE
    , CONSTRAINT HORSE_PK PRIMARY KEY
    HORSE_NAME
    ENABLE
    The message I get is:
    Error at Command Line:48 Column:13
    Error report:
    SQL Error: ORA-02264: name already used by an existing constraint
    02264. 00000 - "name already used by an existing constraint"
    *Cause:    The specified constraint name has to be unique.
    *Action:   Specify a unique constraint name for the constraint.
    This suggests to me that I should change the name to something else, like HORSE_ID. Whilst I don't agree that HORSE_NAME is used in another constraint I have changed the name but it doesn't make a scrap of difference.
    There is another parallel table called HORSES (plural) but but other examples ( eg PUNTER/PUNTERS) have been happily created.
    I would be grateful for any suggestions.
    Thanks,
    Jim

    The message is not specifically about the HORSE_NAME - it is more likely about the table name.
    You probably already have another database object called Horse (maybe not a table but it could be a view or a procedure).
    Try a different name for the table.

  • Trying to create table using Union All Clause with multiple Select stmts

    The purpose of the query is to get the Substring from the value for eg.
    if the value is *2 ASA* then it should come as ASA
    where as if the value is *1.5 TST* the it sholud come as TST like wise for others too.
    I am trying to execute the below written SQL stmt but getting error as:
    *"ORA-00998 must name this expression with the column alias 00998.00000 - Must name this expression with the column alias"*
    CREATE TABLE TEST_CARE AS
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =5
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =14
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
    I want to create the table using the above given multiple select using the Union ALL clause but when trying to create run the query getting error as "ORA-00998 must name this expression with the column alias 00998.00000 - Must name this expression with the column alias"
    Please guide me how to approach to resolve this problem.
    Thanks in advance.

    When you create a table using a SELECT statement the column names are derived from the SELECT list.
    Your problem is that one of your columns is an expression that does not work as a column name SUBSTR(old_care_lvl,3)What you need to do is alias this expression and the CREATE will pick up the alias as the column name, like this:
    CREATE TABLE TEST_CARE AS
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3) column3, len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =5
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =14
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
    );You may not like the name "column3" so use something appropriate.

  • Create Tables using sql.

    Hi Dear;
    can i create tables from SQL enterprise manager and not from SAP-BO without having problem in the upgrade?
    thank you Dear.

    Hi Adele,
    I never heard that there is any issue with additional / custom tables in a B1 <b>company</b> database.
    For certification there is no issue with that - except that you must use your SAP namespace also for these tables.
    For your reference I add here the current links to the page about Solution Certification (B1-SDK) + the Test Plan - which lists all requirements:
    B1-SDK: SAP BUSINESS ONE ADD-ON SOLUTION CERTIFICATION  (B1-SDK) [original link is broken]
    Test Plan: https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/81a22ee1-0701-0010-45aa-ec852e882de3
    Regards,
    Frank
    Message was edited by: Frank Moebius
    PS: Adding tables to SBO-Common is a different game though since it is not expected that a partner adds tables there and <u>eventually</u> additional tables there might get removed during upgrades.
    If you have a need for additional data storage across all companies, please create a dedicated database for that purpose.

  • Error when trying to create tables using "asant create-db_common"

    Hi,
    I'm attempting to run asant create-db_common to use a .sql file to create a table in Pointbase. However I keep getting this error:
    Buildfile: build.xml
    init:
    create-db_common:
         [java] java.lang.NoClassDefFoundError: com/pointbase/tools/toolsCommander
         [java] Exception in thread "main"
    BUILD SUCCESSFUL
    Total time: 1 secondWhich means I need to include the classpath, I presume! But I don't know what file to add it to or where to begin.
    Can anyone help?
    Thanks.

    Still haven't solved this problem.
    Can anyone guide me at all?
    Many thanks.

  • How to Create Table Using Column Drag and Drop Feature

    Hi:
    I am new to Oracle SQL dev Data Modeler tool and would like to know if there is a way to create a new table by re-using the existing columns or column groups. The idea is to maintain consistency and save table design time. If columns created previously can be re-used and require drag and drop of column in the right pane, then only new columns need to be manually created.
    Any thoughts on this will be appreciated.
    Thanks!

    Hi Kent
    I checked out the video and tried it in Oracle designer, it works and works great!
    My other question is that I may have several set of columns that I may want to group depending on the table requirements. Can I have multiple templates and choose which one to apply to?
    Also, how do I choose the table where the table template needs to be applied. As I may be interested in applying the table template to selected tables only.
    Thanks
    Edited by: user648132 on Feb 20, 2012 10:47 AM

  • BC4J tag - add new record only in child table using join query

    Hi,
    I have developed the struts base jsp for BC4J component application using jdeveloper wizard.
    i have first developed the BC4J component. using emp table and dept table,
    also developed the association between emp and dept , and create view object using created association.
    when i haae developed the the struts base jsp for BC4J applicaion using alerady created view object. it creates automatically DataEditComponent.jsp and DataTableComponent.jsp and etc...
    and when i want to add new row or record it automatically add the entry in both table ,
    in above scenario i have used dept as master and emp as child table.
    what is the solution , if i want to add row or record in only emp table.
    please help me

    Hi Reetesh,
    I have written following code into the ADD ROW button
    System.out.println("Coming in Click Event");
    OAApplicationModuleImpl am = (OAApplicationModuleImpl) pageContext.getApplicationModule(webBean);
    OAWebBean innerTablebean = (OAWebBean)webBean.findChildRecursive("region12");
    OATableBean innerTable = (OATableBean)webBean.findChildRecursive("innerTablebean");
    OAInnerDataObjectEnumerator enum = new OAInnerDataObjectEnumerator(pageContext,innerTablebean);
    while(enum.hasMoreElements())
    RowSet innerRowSet = (RowSet) enum.nextElement();
    Row []rowsInRange = innerRowSet.getAllRowsInRange();
    OARow newRow = (OARow) innerRowSet.createRow();
    OADBTransaction dbt = am.getOADBTransaction();
    Number b = dbt.getSequenceValue("PK_XX_BATCH_PROGRAM_PARAMETERS");
    newRow.setAttribute("ProgramId", b);
    newRow.setAttribute("ProgramParmId",b);
    newRow.setAttribute("ParameterName",new String(""));
    newRow.setAttribute("ParameterDataType",new String(""));
    newRow.setAttribute("ParameterInOutType",new String(""));
    innerRowSet.insertRow(newRow);
    Now the problem occurs only when there are more than one rows in parent table... As many rows are there in parent table that many times the rows are being added.
    With Regards,
    Sandip

  • Creating tables using arrays.

    Hi, i have 3 arrays whose size may differ depending on a text file. I used vectors and string tokenizers to read the data and split them into 2 vectors, The third one is an array created from the values in vector2 using a formula. Now, I need to create a table with the 3 columns and the number of rows depending on the length of the array3 which is the same as vector 1 and vector2.
    How do i do that? The col1 in the table shoud have the data in vector1, col2 should have data in vector2 and col 3 should have data in array3.
    Please help me in this
    Thanks

    I have to display this data in the form of a "table"
    where the data in the columns are the data in the
    three arrays. I have to display this is an array. I believe you can create an array from a List, and a Vector is a List.
    Look at java.util.*. If this is what you mean.
    The problem is, the size of vectors depends on various
    calculations. so it is not the same everytime. So i
    need to display the data depending on the vector's
    size.How is this a problem? You can get the size from the vector, then use that for whatever kind of table you're making, probably. I still have no idea what kind of table you mean.

  • Problem in Creating Table using DB Config. Assistant

    Hi, everybody. I see the error messages below when I use DB Configuration Assitant in Oracle 8i to create my database :-
    ORA-01034 : Oracle not available
    ORA-27146 : post/wait initializtion failed
    ORA-01012 : not logged on
    Can u tell me how to solve this problem ?

    Connect as servermanager and enter on the prompt
    "lsnrctl status" it will give you whether you have started the listener service and after that connect as internal and "startup" if the database is started it will give message "database instance already started" or else it will start the database.
    also make sure you have created all control files properly
    Nadeem

Maybe you are looking for

  • Macbook Pro 8,2 - No Microphone

    I've recently needed to install Skype on my computer for work. Unfortunately, while the webcam seems to work fine, there is no audio being recorded. I tried recording via arecord, and the sound file produced contains no sound. My alsamixer gives me t

  • Problem in to_char function

    hi, when i am using select to_char(sysdate,'dd.mm.yy') from dual* then its giving the right answer 27.09.10. but when i am replacing the sysdate with the particular date format of oracle that is select to_char('27-Sep-10','dd.mm.yy') from dual* then

  • Using ref cursor in "in clause" in select statement

    Hi, Is there any way can we use the ref cursor in the in condition of a select statement. Regards, Venkat. Edited by: ramanamadhav on Aug 23, 2011 11:14 AM

  • Function module to find the columns in Internal table

    Hi Group, Is there any function module which displays the columns of the internal table. I guess there is one cos when we debug any program and select the "Tables" button while debugging and enter an internal table and then do a "Find" the pop up whi

  • HINTS and VIEWS question

    Hi I trying to optimise the query on a 6 table view.  From looking at the way the view is queried and the columns that some tables provide (several tables only provide a single column in the view definition) I have created indexes for 3 of the tables