functional relations sql query (commented out for now)