Search This Blog

Friday, June 24, 2011

MySQL Insert statement with nested CASE and SELECT

The MySQL manual is a little bit confusing so I just wanted to give an example of MySQL’s insert statement with nested CASE and SELECT.

INSERT INTO TEST (startdate, testname, ipaddress, hostname, customerid, application)
  CASE count(id)
      WHEN 1 THEN id
      ELSE (SELECT id FROM customer where customername like '%OTHER%')
  FROM customer WHERE CUSTOMERNAME like '%XXX%';

1 comment:

If you like this post, please leave a comment :)