updated complex select statement