Consider following 3 column table structure:
id, b_time, b_type
id is a string, there will be multiple rows with the same id in the table.
b_time is timestamp and b_type can have any one of 2 possible values - 'A' or 'B'.
I want to select all the rows that fulfill one of the 2 conditions, priority wise:
For all ids, select the row with highest timestamp, where b_type='A'.
If for an id, there are no rows where b_type='A', select the row with highest timestamp, irrespective of the b_type value.
Please suggest the sql query which should tackle this problem(even if it requires creation of temporary intermediate tables).