Ray writes "Hi from Australia guys,We have two tables: tblProducts and tblMemberPrice (See schema below), users visiting the site may be members and will have a memberType (Integer Eg. 1) assigned to them.We want to list all the products and prices from tblProducts and if a matching record for the product is found in tblMemberPrice it needs to use that price instead.Each product may have mutiple entries in tblMemberPrice with the memberType number different for different member levels.Eg.priceID 1productID 1memberType 1amount 100priceID 2productID 1memberType 2amount 90
So the query would need to only return results where the users memberType matched (Eg. WHERE memberType=1)As soon as you specify 'memberType=1' in the WHERE clause, it excludes any entries that don't have a matching entry in tblMemberPrice.Currently we're looking at making a separate query for each product which is a lot more of an overhead on the server.Is there a way with one SQL query to list all the products, and return any applicable member prices if there is a matching entry in tblMemberPrice?Looking forward to a possible solution.Schema of tblProducts and tblMemberPrice---------------------tblProducts---------------------productID (Int - Identity)productName (nvarChar)salePrice (money)----------------------------------------tblMemberPrice---------------------priceID (Int - Identity)productID (int)memberType (Int)amount (money)---------------------
"