Query to select max value on join I have a table of Users:

|Username|UserType|Points|
|John    |A       |250   |
|Mary    |A       |150   |
|Anna    |B       |600   |


and Levels

|UserType|MinPoints|Level  |
|A       |100      |Bronze |
|A       |200      |Silver |
|A       |300      |Gold   |
|B       |500      |Bronze |


And I'm looking for a query to get the level for each user. Something along the lines of:

SELECT *
FROM Users U
INNER JOIN (
    SELECT TOP 1 Level, U.UserName
    FROM Levels L
    WHERE L.MinPoints &lt; U.Points
    ORDER BY MinPoints DESC
    ) UL ON U.Username = UL.Username


Such that the results would be:

|Username|UserType|Points|Level  |
|John    |A       |250   |Silver |
|Mary    |A       |150   |Bronze |
|Anna    |B       |600   |Bronze |


Does anyone have any ideas or suggestions on how could I do this without resorting to cursors?
Your existing query is close to something that you could use but you can get the result easily by making a few changes.  By altering your query to use the APPLY operator and implementing CROSS APPLY.  This will return the row that meets your requirements.  Here's a version that you could use:

SELECT 
  u.Username, 
  u.UserType,
  u.Points,
  lv.Level
FROM Users u
CROSS APPLY
(
  SELECT TOP 1 Level
  FROM Levels l
  WHERE u.UserType = l.UserType
     and l.MinPoints &lt; u.Points
  ORDER BY l.MinPoints desc
) lv;


Here's a SQL Fiddle with a demo.  This produces a result:

| Username | UserType | Points |  Level |
|----------|----------|--------|--------|
|     John |        A |    250 | Silver |
|     Mary |        A |    150 | Bronze |
|     Anna |        B |    600 | Bronze |