Select im_screen_name from jb_screens where user_id = :user_id and service = 'jabber' Select screen_id from jb_screens where im_screen_name = :screen_name and service = 'jabber' update jb_screens SET refcount = refcount + 1 where im_screen_name = :screen_name and service = 'jabber' insert into jb_friends (user_id , friend_screen_id) values (:user_id , :screen_id)