diff --git a/src/database/queue.c b/src/database/queue.c
index 0ddba99071590b562f67472b12064b933cec9c50..ed6ddc6f5882527407c52c9fd4d858bfa2b0eec3 100644
--- a/src/database/queue.c
+++ b/src/database/queue.c
@@ -568,11 +568,13 @@ database_queue_shuffle(volatile sqlite3 *db)
     const char *SQL =
         "BEGIN TRANSACTION;"
         /* Create temporary queue */
-        "CREATE TEMPORARY TABLE queue_tmp"
+        "CREATE TEMPORARY TABLE IF NOT EXISTS queue_tmp"
         "  ( position INTEGER PRIMARY KEY AUTOINCREMENT CHECK(position > 0)"
         "  , kara_id INTEGER"
         "  , priority INTEGER NOT NULL DEFAULT 1 CHECK(priority > 0 AND priority < 6)"
         "  );"
+        "DELETE FROM sqlite_sequence WHERE name = 'queue_tmp';"
+        "DELETE FROM queue_tmp;"
         /* When current is NULL, that thing is also NULL, so no insertion is done */
         "INSERT INTO queue_tmp (kara_id, priority)"
         "  SELECT kara_id, 5"
@@ -594,8 +596,6 @@ database_queue_shuffle(volatile sqlite3 *db)
         "  SELECT position, kara_id, priority"
         "  FROM queue_tmp"
         "  ORDER BY priority, position;"
-        "DROP TABLE queue_tmp;"
-        "DELETE FROM sqlite_sequence WHERE name = 'queue_tmp';"
         /* Set the current to the right kara when needed */
         "UPDATE queue_state"
         "  SET current = CASE"