Only get records with the best source

bullseye09

New Member
Joined
Sep 24, 2015
Messages
2
I have a dataset in Access with with multiple sources. So each item in the data has 1 or more records with different data. I would like to make a query to return only the record for each item with the best data source available. I have made a column in which I've numbered the sources with the lowest number being the best source. Figured I could make something with a MIN() function but haven't been able to get it to work.

So basically I want to take data like this:

ItemSOURCESource RankDataMoreData
1ABC10.419360.10836
1DEF20.152150.19984
1GHI30.693860.82899
2DEF20.909190.26663
2GHI30.506440.08439
3DEF20.791230.77338

<colgroup><col><col><col><col span="2"></colgroup><tbody>
</tbody>

And return this:

ItemSOURCESource RankDataMoreData
1ABC10.419360.10836
2DEF20.909190.26663
3DEF20.791230.77338

<colgroup><col><col><col><col span="2"></colgroup><tbody>
</tbody>

I've been struggling to make a query that does this. Can anyone help?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You need to use two queries, the first one takes the min of Source Rank for each Item in MasterTable. (MasterTable is the first table in your post.) You can copy and paste this code in the SQL view for a query and save as "01: Get MinOfSource".

Code:
SELECT MasterTable.Item, Min(MasterTable.[Source Rank]) AS [MinOfSource Rank]
FROM MasterTable
GROUP BY MasterTable.Item;

Get_Min.png


The second query joins MasterTable to the query above selecting only the minimum source ranks:

Code:
SELECT MasterTable.Item, MasterTable.SOURCE, MasterTable.[Source Rank], MasterTable.Data, MasterTable.MoreData
FROM MasterTable INNER JOIN [01: Get MinOfSource] ON (MasterTable.Item = [01: Get MinOfSource].Item) AND (MasterTable.[Source Rank] = [01: Get MinOfSource].[MinOfSource Rank]);

Show_Best.png
 
Upvote 0

Forum statistics

Threads
1,221,842
Messages
6,162,333
Members
451,759
Latest member
damav78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top