Retrieving Records with Max Values using TOP

I know I know, it’s a horrible title. If anyone has a better suggestion please let me know!

Here’s what I’m talking about:

I have two tables; the first table contains unique records describing games and the second contains game ids, scores, and user ids. Game id is joining the first table to the second in a one to many, something like this:

Games
======
gameID
gameName

GameScores
=========
gameID
userID
score

MY MISSION: Retrieve the user with the high score for each game in one query.

After much trial, error, and gnashing of teeth, the solution, as usual, proved to be ridiculously simple:


SELECT (select top 1 userID from GameScores where gameID = Games.gameID order by score desc) as topScoreUser,
                Games.gameName,Games.gameID, s.score
FROM Games
JOIN   GameScores s on s.gameID = Games.gameID

What this does is return one record for each game. Since I’m only returning the top record in the query and I’m ordering by score in descending order, I’m getting the top score and player for each game.

I’ve run into quite a few instances now where TOP has proved invaluable. Unfortunately it always seems to take me an hour of futzing around before I remember to use it!

-rG

How to Get Flash AS2 to Display Italicized HTML Text

Wacky Flash quick tip #127:

A co-worker of mine recently asked me how to get italics to appear in a Flash html Text Field. Use the i tag I told him but he said he tried that and the text disappeared altogether. Assuming he was deranged I quickly opened a new Flash document and attempted to demonstrate what I was talking about.

I created a dynamic text field, marked it as html, embedded my font, gave it an instance name, wrote a little AS to populate it and hit CTRL-ENTER. To my surprise, there was no text on the stage. After retracing my steps to make sure I didn’t miss anything I tried again to make sure. Nope, still not working. It ended up taking me about 20 minutes to figure out.

Here’s the trick:
You have to place a dynamic text field on the stage for each style of the font you want to use. For example, the string I’m using to populate the field is “hello there”, so I had to place one dynamic text field with the italic font style embedded and another embedded with no style. Once that was done it worked perfectly.

I thought the whole process was pretty bizarre which is why I’m posting it. If it doesn’t benefit anyone else at least it’ll be here for my own personal reference 😉 .

If you’re interested, here’s a .fla to demonstrate.