postgresql7.1 select pr.first_names , pr.last_name , (pr.person_id) as any_user_id , sn.screen_id, sn.status, sn.service, sn.im_screen_name from persons pr , jb_screens sn where pr.person_id = sn.user_id and lower(pr.last_name) like(lower('$prefix%')) and sn.user_id != :user_id and sn.user_id NOT IN ([template::util::tcl_to_sql_list $all_invisible]) and ( (sn.status != 'offline') OR sn.user_id IN ([template::util::tcl_to_sql_list $onliners]) ) and sn.screen_id not in (Select friend_screen_id from jb_friends where user_id = :user_id) ORDER BY any_user_id select pr.first_names , pr.last_name , (pr.person_id) as any_user_id , sn.screen_id, sn.status, sn.service, sn.im_screen_name from persons pr , jb_screens sn where pr.person_id = sn.user_id and sn.user_id != :user_id and sn.user_id NOT IN ([template::util::tcl_to_sql_list $all_invisible]) and ( (sn.status != 'offline') OR sn.user_id IN ([template::util::tcl_to_sql_list $onliners]) ) and sn.screen_id not in (Select friend_screen_id from jb_friends where user_id = :user_id) ORDER BY last_name