Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INNER JOIN and min value

Status
Not open for further replies.

dubr12

Programmer
Aug 8, 2012
2
HR
Hi,
I have two tables. In one are apartment data - "apart" table(site for renting apartments). In other are prices - "prices" table. There are more than one price for one apartment (from 01.8.2012- 31.08.2012 is 50 Eur, 01.09.2012 - 31.12.2012 is 45,...). Two tables are connected with rentalid field. I want to get only lowest price. I have query that gives me all prices for one apartment. I get for example apartment1 with price 50Eur, then again apartment1 with price 45Eur. I need only to show price 45Eur. Here is the code:

"SELECT apart.apname, apart.rentalid, apart.status, apart.statpicture, apart.peoplebasic, apart.sdescription, apart.picture1, apart.bedrooms, apart.maxpeople, apart.arem2, prices.grosspr from apart INNER JOIN prices ON apart.rentalid = prices.rentalid WHERE prices.pricedateto > Date() ORDER BY apart.apname"

Please help

Thanks
 
Try
SQL:
SELECT apart.apname, apart.rentalid, apart.status, apart.statpicture, 
apart.peoplebasic, apart.sdescription, apart.picture1, apart.bedrooms,
apart.maxpeople, apart.arem2, Min(prices.grosspr) as MinPrice
FROM apart INNER JOIN prices ON apart.rentalid = prices.rentalid 
WHERE prices.pricedateto > Date() 
GROUP BY apart.apname, apart.rentalid, apart.status, apart.statpicture, 
apart.peoplebasic, apart.sdescription, apart.picture1, apart.bedrooms,
apart.maxpeople, apart.arem2
ORDER BY apart.apname

Duane
Hook'D on Access
MS Access MVP
 
Thanks you for your answer, but it doesnt work. When I click search button nothing happend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top