Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

SQL help - one to many relationships?

Thread Tools
 
Search this Thread
 
Old 04 March 2003, 12:30 PM
  #1  
Fosters
Scooby Regular
Thread Starter
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

Select i.investment_name, i.investment_type, v.valuation_date, v.valuation_amount
from tbl_investment i
inner join tbl_valuation v on i.investment_id=v.investment_id
where v.valuation_date=(select max(t.valuation_date)
from tbl_valuation t where t.investment_id = i.investment_id)

that sort of thing?

(edit, put the join in)

[Edited by Fosters - 4/3/2003 12:32:57 PM]
Old 03 April 2003, 11:12 AM
  #2  
AdrianFRST
Scooby Regular
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
Question

I have an sql problem that I can't figure out. It relates to investments and valuations of those investments at certain dates.


tbl_investment has details of the investment:
---------
investment_id
investment_name
investment_type

tbl_valuation holds the valuations and the dates they took place:
---------
valuation_id
investment_id
valuation_date
valuation_amount


An investment can have many valuation_amounts.

How can I run a select query that returns all the data from tbl_investment but only the most recent valuation_amount from tbl_valuation?

Doing a simple join returns all the valuations, Select Top 1 returns only the first row from tbl_prod and I everything I've tried with select(min) or select(distinct) either doesn't give what I want or is bad syntax.

I need to run this query to return the complete list of investments in tbl_investment, not just the first one, or a specific one.

Thanks!
Old 03 April 2003, 11:56 AM
  #3  
AdrianFRST
Scooby Regular
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
Post

Exactly what I was after thanks!
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
stevem2k
Non Scooby Related
8
06 July 2011 11:11 PM
Kevin Mc
Computer & Technology Related
8
27 March 2002 10:24 AM
dsmith
Computer & Technology Related
4
13 February 2002 12:38 PM
Puff The Magic Wagon!
Computer & Technology Related
3
02 February 2002 04:04 PM
SDB
Non Scooby Related
2
26 May 2001 11:55 PM



Quick Reply: SQL help - one to many relationships?



All times are GMT +1. The time now is 12:29 AM.