Select from Insert

September 22, 2011


People imagination has no limits. Where does it lead SQL? Here is some bizarre syntax:

SELECT column1
  FROM FINAL TABLE
  (INSERT INTO t1 VALUES(1,'John Smith') )

Wow, a whole semicolon has been spared — at the expense of syntax confusing relation with operator!

You would think DB2 designers would become laughing stock of SQL community? Wrong. Be prepared for some competition:

WITH sal1 AS
(
   SELECT * FROM NEW
   (
     INSERT INTO EMPLOYEES(EMPLOYEE_ID, SALARY) VALUES(207, 1000)
   )
)
, sal2 AS
(
   SELECT * FROM NEW
   (
     UPDATE EMPLOYEES SET SALARY = SALARY*1.1
   )
)
SELECT * FROM EMPLOYEES;

Then, why not INSERT as SELECT FROM (INSERT as SELECT), and so on.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: