functions to start building complex sql queries