Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL Query for Selecting informaitno in a Group

$
0
0

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


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>