SQL query creation

implemented query creation