<script src="http://alasql.org/console/alasql.min.js"></script>
Before update:
<div id="res1"></div>
After update:
<div id="res2"></div>
JavaScript
// Generate two arrays
alasql('CREATE TABLE one (a INT PRIMARY KEY, b INT)');
for(var i=0;i<3;i++) {
alasql('INSERT INTO one VALUES (?,?)',[i, i]);
}
alasql('CREATE TABLE two (a INT PRIMARY KEY, b INT)');
for(var i=0;i<7;i++) {
alasql('INSERT INTO two VALUES (?,?)',[i, i*100]);
};
alasql('SELECT * INTO HTML("#res1", {headers:true}) FROM one');
for(var i=2;i<6;i++) {
alasql('IF EXISTS(SELECT * FROM one WHERE a=$[0]->a) UPDATE one SET b = $[0]->b WHERE a=$[0]->a ELSE INSERT INTO one VALUES ?',[{a:i,b:i*i}]);
}
alasql('SELECT * INTO HTML("#res2", {headers:true}) FROM one');
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.
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!
Console
Debug your Fiddle with a minimal built-in JavaScript console.