<script src="http://alasql.org/console/alasql.min.js"></script>
<div id="res"></div>
<script type="text/sql" id="sql">
CREATE TABLE people (
Id INT PRIMARY KEY,
FirstName STRING,
LastName STRING);
INSERT INTO people VALUES
(1,"Peter","Peterson"),
(2,"Eric","Ericson"),
(3,"John","Johnson");
IF EXISTS (SELECT * FROM people WHERE Id=2)
UPDATE people SET FirstName = "Roll", LastName = "Rolson" WHERE Id=2
ELSE
INSERT INTO people VALUES (2,"Eric","Rollson");
IF EXISTS (SELECT * FROM people WHERE Id=4)
UPDATE people SET FirstName = "Roll", LastName = "Rolson" WHERE Id=4
ELSE
INSERT INTO people VALUES (4,"Smith","Smithson");
SELECT * INTO HTML("#res",{headers:true}) FROM people;
</script>
JavaScript
alasql('SOURCE "#sql"');
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!