Q:

MySQL select help; Subquery?

I have two tables that I'm querying from. In one table, there are fields which denote if a player featured on a photo is dead/alive, in the Hall of Fame, etc. The field that I just added is called "new_flag". This denotes whether the photo is new to my inventory
Without a GROUP BY, the results would look something like this (Note some players have more than one product/photo)
name            firstname  lastname     hall_of_fame  deceased  new_flag
----            ---------  --------     ------------  --------  --------
EARL AVERILL SR EARL       AVERILL SR   Y             Y         Y
BILL TERRY      BILL       TERRY        Y             Y         N
BILL TERRY      BILL       TERRY        Y             Y         Y
BILL TERRY      BILL       TERRY        Y             Y         N
BOBBY DOERR     BOBBY      DOERR        Y             N         N
BOBBY DOERR     BOBBY      DOERR        Y             N         N

With a GROUP BY my query looks like this, but it cannot always find the new flag since each player may have more than one record.
SELECT    CONCAT(a.firstname,' ',a.lastname) AS name,
          a.firstname,
          a.lastname,
          b.hall_of_fame,
          b.deceased,
          b.new_flag
 FROM     vm_product_name AS a,
          vm_product_new_attribute AS b  
 WHERE    b.hall_of_fame ='Y'
   AND    a.product_id = b.product_id
 GROUP BY CONCAT(a.firstname,' ',a.lastname)
 ORDER BY a.lastname,
          a.firstname;

The problem is that I only only want each player to appear once on my webpage, but.....I also want to add a "new" icon next to the player's name if they have at least 1 new photo. Any ideas how I can do this?
I know this is not the optimal way to do this, but it is built as a Joomla/Virtumart extension and I cannot change the database structure at this time.

A:

SELECT CONCAT(a.firstname, ' ', a.lastname) AS name, a.firstname, a.lastname,
    b.hall_of_fame, b.deceased, MAX(b.new_flag) AS new_flag
FROM vm_product_name AS a
    INNER JOIN vm_product_new_attribute AS b
        ON a.product_id = b.product_id
WHERE b.hall_of_fame = 'Y'
GROUP BY a.lastname, a.firstname
ORDER BY a.lastname, a.firstname

