Fix some sql compositions
Merge pull request #783 from romainneutron/composed-db-queries

[3.9] Fix some sql compositions