I would like to get information for each group of order_number,
there will be only maximum two records (A & B) for each group (e.g. AB002231)
There may be cases for
a) both A & B records contains the product code, we get the first record
b) only one record (A or B) contains the prduct code, we get the record with product code (A or B)
c) only one record exists (get it even it is NULL)
Example table 'Purchases'
order_number | product_code | price
a)
AB002231A | AAA | 200
AB002231B | ABC | 100
b)
AC003300A | DEF | 200
AC003300B | NULL |NULL
c)
AC003447A | NULL | NULL
...
Any suggestion on the SQL query that can obtain the following results, thanks.
AB002231A | AAA | 200
AC003300A | DEF | 200
AC003447A | NULL | NULL