Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two tables in my access database one is product_details and another is bid_details.

i want to show all the product_details in a gridview with highest bid of respective products which is stored in a bid_details table. i want to show only highest bid of the product as there are so many bids in bid_details table..

Product_id column is a primary key in both talbes.

Hope you will solve my problem..
Posted

1 solution

Problem 1: Same data [product_id] primary key in both tables? Then why bother with two tables? You declared a 1:1 relationship between products and bids.

In practice, the bid table should be using the product_id of product_details as a foreign key . Now you can have multiple bids referred to by a single product.

Once that is done, there are several methods to get your desired result.

Not knowing your table layout, here's the gist of it:

- Group by the product_id in the bid_details table and use MAX(bid-field)
- JOIN the result of this to the product_details table.

I deliberately didn't specify which type of join because I don't know how you wish to handle products that have no current bids (perhaps, handle with ISNULL(bid, 0) ?)

UPDATED: Per your reply
Something like:
SELECT A.item_name, MAX(B.bid) as Bid
FROM product_details as A INNER JOIN bid_details as B
ON A.product_id = B.product_id
GROUP BY A.item_name, B.product_id


But remember, the above relies upon you have tables set up as I alluded to in the first part of this answer.
 
Share this answer
 
v2
Comments
Harpreet_125 6-Nov-13 13:11pm    
i am not good in sql.. thats why i am asking :)
Harpreet_125 6-Nov-13 13:12pm    
please give any sample of doing this..
W Balboos, GHB 6-Nov-13 13:29pm    
Answer has been updated, q.v.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900