Retrieve the Apple ID used to download a given app (in iphone)

On your phone you can use the Setting app to set the default ID for App Store under "iTunes and App Store"

Set ID1.

Open App Store -> Updates. At the top you can click Purchased to see all apps purchased with that account.

Then, go back to settings, sign in to ID2, and go back to the App Store and check to see ID2s list.