Finding newest or flagged row in a one to many relationship in MySQL -
sorry if title poor, i'm trying join primary table related table , return single row matches flagged or recent row in related table. primary table, let's call group, has columns: id, name related table, let's call user, has columns: id, group_id, email, default, updated_datetime the query should return single 'group', , either matching record 'user' default=1 (preferred), or if no rows have default=1 row max(updated_datettime). 'user' have 1-n rows group.id = user.group_id. example result: group.id, group.name, user.email, user.default, user.updated_datetime 1, 'test', 'email', '0', '2015-06-10 12:00' 2, 'other', 'email', 1', '2015-06-08 10:00' both tables contain lot of data i'd prefer join's , not subqueries. know how subqueries i'm having trouble doing joins since grouping has multiple conditions. i'm fine doing aliases, eg: select a.* (query) i