I suspect the answer is "no" but I thought I'd ask cause if the answer is "yes" then I can eliminate a huge step from my code and make it a lot less ugly.
I have a database which looks something like this:
user_id | badge_id | value
Now, a given user can have an indeterminate number of rows in this table, so one user might have 0 rows and another might have as many as 100 (it's never more than that).
Currently I have a really nasty call where I have 100 subselect "columns" where I select a specific badge_id for a given user... so it looks (in pseudo code, like this)
select user_id as uid,
(select value from badges where badge_id = 1 and user_id = uid) as badge_1,
(select value from badges where badge_id = 2 and user_id = uid) as badge_2
etc etc 98 more times
This query is being assembled programmatically as a String by the surrounding (Javascript) code that first does a preliminary query to get all the various badge ids.
I'm wondering if there's some way to do a select for all the badge ids and then make the call above dynamically within SQL itself (without using stored procedures).
All ideas welcome