Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Table Through JOIN SQL

I need to create a new table in my database through a left join statement of two tables from different schemas. Here is my code below:

CREATE TABLE NEW_TABLE
  FROM SCHEMA_1.TABLE_A X
  LEFT JOIN SCHEMA_2.TABLE_B Y
     ON X.NAME = Y.NAME 
        AND X.NUMBER = Y.NUMBER

I'm getting a SQL error:

ORA-00922: missing or invalid option
00922. 00000 - "missing or invalid option"

like image 604
Roy Young Avatar asked Oct 27 '25 10:10

Roy Young


1 Answers

You are missing the as select clause:

CREATE TABLE NEW_TABLE
AS ( -- This was missing
    SELECT    * -- So was this
    FROM      SCHEMA_1.TABLE_A X
    LEFT JOIN SCHEMA_2.TABLE_B Y ON X.NAME = Y.NAME AND
                                    X.NUMBER = Y.NUMBER
   )
like image 187
Mureinik Avatar answered Oct 30 '25 00:10

Mureinik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!