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 | 01:30 PM
  #1  
Fosters's Avatar
Fosters
Thread Starter
Scooby Regular
 
Joined: Jul 2000
Posts: 2,145
Likes: 0
From: Islington
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 | 12:12 PM
  #2  
AdrianFRST's Avatar
AdrianFRST
Scooby Regular
 
Joined: Oct 2000
Posts: 368
Likes: 0
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 | 12:56 PM
  #3  
AdrianFRST's Avatar
AdrianFRST
Scooby Regular
 
Joined: Oct 2000
Posts: 368
Likes: 0
Post

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




All times are GMT +1. The time now is 05:17 PM.