database - Do conditional INSERT with SQL? -


i have database updated datasets time time. here may happen dataset delivered exists in database.

currently i'm first doing a

select ... val1=... , val2=... 

to check, if dataset these data exists (using data in where-statement). if not return value, i'm doing insert.

but seems bit complicated me. question: there kind of conditional insert adds new dataset in case not exist?

i'm using smallsql

you can single statement , subquery in relational databases.

insert targettable(field1)  select field1 mytable not(field1 in (select field1 targettable)) 

certain relational databases have improved syntax above, since describe common task. sql server has merge syntax kinds of options, , mysql has optional insert or ignore syntax.

edit: smallsql's documentation sparse parts of sql standard implements. may not implement subqueries, , such may unable follow advice above, or anywhere else, if need stick smallsql.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -