diff --git a/pyprophet/levels_contexts.py b/pyprophet/levels_contexts.py
index <HASH>..<HASH> 100644
--- a/pyprophet/levels_contexts.py
+++ b/pyprophet/levels_contexts.py
@@ -419,8 +419,6 @@ def merge_osws(infiles, outfile, templatefile):
     c.executescript('''
 PRAGMA synchronous = OFF;
 
-ATTACH DATABASE "%s" AS sdb;
-
 DROP TABLE IF EXISTS RUN;
 
 DROP TABLE IF EXISTS FEATURE;
@@ -443,6 +441,8 @@ DROP TABLE IF EXISTS SCORE_PROTEIN;
 
 DROP TABLE IF EXISTS SCORE_IPF;
 
+ATTACH DATABASE "%s" AS sdb;
+
 CREATE TABLE RUN AS SELECT * FROM sdb.RUN LIMIT 0;
 
 CREATE TABLE FEATURE AS SELECT * FROM sdb.FEATURE LIMIT 0;
[FIX] Patch for merging of subsampled runs