Coding conventions (sql queries)

Rewritten the sql queries that use straight_join according
to coding conventions, for compatibility with non-mysql db

Change-Id: I9bec69cc842ff618c58e51e49d6c980a1b36b37a
Merge "Coding conventions (sql queries)"