This query will give you the lowest rank for each sku where the price in tbl_1 is greater than the price in tbl_2
SELECT sku, MIN(Rank) AS Rank
FROM tbl_1 INNER JOIN tbl_2 ON tbl_1.sku = tbl_2.sku AND
tbl_1.price >= tbl_2.price
Now to get the actual tbl_1 record, you need to join this back to tbl_1:
SELECT tbl_1.*
FROM tbl_1 INNER JOIN (SELECT sku, MIN(Rank) AS Rank
FROM tbl_1 INNER JOIN tbl_2 ON tbl_1.sku = tbl_2.sku AND
tbl_1.price >= tbl_2.price) A
ON tbl_1.sku = A.sku and tbl_1.rank = A.rank
SQL Server Helper
How well do you know SQL? Find out with the free test assessment from SQL Server Helper!!!
http://www.sql-server-helper.com/free-test/default.aspx
Got a SQL Server Question? Ask us here:
http://www.sql-server-helper.com/forums/default.asp