I can get the badge id for a specific user, for example query:
Select *
From Badges
Where UserId = 10907521
Example badge id from result
30884218
But, how is it possible to get the associated question or answer id (if applicable) for every badge awarded to a user?
For those badges which are not related to a Q&A, we could expect an "NA".
Badge awards and posts are not linked in SEDE; that information is not available in the Data Explorer.
You could get it from the API, though it ain't pretty.
Reference the:
Usage of /users/{ids}/timelineroute/me/timelineroute (which requires OAuth)For example, fetching:
/users/10907521/timeline?pagesize=100&site=stackoverflow
returns results like:
once you filter/search for
badge_idin the results