Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
obinna
Starting Member
26 Posts |
Posted - 2007-06-15 : 05:17:58
|
| I have a Property Database with 2 tablesTable Property = PropertyID (PK), PropertyStreetname etcTable PropertyTracker = PropertyID (FK),Price, PropertyPriceID(PK) So I have One To Many RelationShip with Property Table and PropertyTrackerHow Do I get the current PropertyPrice from the two tables, my sub query failsSELECT dbo.tbl_Property.PropertyID,PRICES =(SELECT PriceFROM dbo.tbl_PropertyTrackerWHERE PropertyID = PropertyID)FROM dbo.tbl_PropertyTracker INNER JOIN dbo.tbl_Property ON dbo.tbl_PropertyTracker.PropertyID = dbo.tbl_Property.PropertyIDThis is the errorServer: Msg 512, Level 16, State 1, Line 1Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-15 : 05:22:58
|
| What do you mean by "Current" property price? Is there any date field in PropertyTracker table?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-15 : 05:27:47
|
| So you want to maintain a datetime column in the PropertyTracker table so that it will be easy to get the latest price of the property.If ur sure that the price of the property keep increasing then no need of datetime column, max price will give you the latest price.--------------------------------------------------S.Ahamed |
 |
|
|
obinna
Starting Member
26 Posts |
Posted - 2007-06-15 : 05:32:04
|
| Yes in the PropertyTracker Table I have DateAdded, IsCurrent which is Bit, I want to retrieve the last Price inserted on the PropertyTracker. I hope I am clear Thanks |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-15 : 05:38:36
|
| Select * from dbo.tbl_Property P join(SELECT PropertyID, datecol, priceFROM dbo.tbl_PropertyTracker PTwhere datecol = (Select max(datecol) from dbo.tbl_PropertyTracker where propertyid = Pt.propertyid)group by PropertyID ) spt on p.PropertyID = spt.PropertyID--------------------------------------------------S.Ahamed |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-15 : 05:41:30
|
| [code]Select p.PropertyId, pt.PriceFrom tbl_Property p JOIN tbl_PropertyTracker pton p.PropertyID = pt.PropertyIDJoin(select PropertyID, max(DateAdded) as DateAddedFrom tbl_PropertyTrackerGroup by PropertyID) ton pt.PropertyID = t.PropertyID and pt.DateAdded = t.DateAdded[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|
|
|