Correct sql query for changed motifs