Close tables all
Set date british
Set century off
Grig,

Select 0
Create Cursor car (Id I, Serial C(10), Model C(20))
Insert into car values (1, "A01", "Ford")
Insert into car values (2, "A02", "Vauxhall")
Insert into car values (3, "A03", "Austin")
Insert into car values (4, "A04", "BMW")
Insert into car values (5, "A05", "Mercades")

Select 0
Create Cursor Reg (Id I, CarId I, RegNumber C(10), Regdate D)
Insert into Reg values (1, 1, "A1029", {^2004/01/01})
Insert into Reg values (1, 1, "A1029", {^1994/01/01})
Insert into Reg values (1, 2, "C1029", {^2004/02/01})
Insert into Reg values (1, 3, "C1029", {^2004/03/01})
Insert into Reg values (1, 3, "C1029", {^2005/01/02})
Insert into Reg values (1, 4, "D1029", {^2004/01/01})
Insert into Reg values (1, 5, "E1029", {^2004/05/01})

Select all ;
  Car.Id                        as CarId, ;
  Car.Serial            as Serial, ;
  Reg.RegNumber         as RegNumber, ;
  Max(Reg.RegDate)      as Date ;
>From Car ;
Join Reg on Reg.Id=Car.Id ;
where .T. ;
Group by Car.Id, Car.Serial, Reg.Regnumber ;
order by Car.Id, Car.Serial, Reg.Regnumber

Dave Crozier

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Grigore Dolghin
Sent: 02 March 2008 15:18
To: [EMAIL PROTECTED]
Subject: SQL Select help needed

It seems I am missing something obvious, however I can't figure out what.

I have two tables, 1-to-many related. Parent table contains car information,
child table contains the registration numbers, with their date, as they
change.

Parent table fields:

Id, Serial, Model

Child table fields:

Id, CarId, RegNumber, RegDate


How the heck the SQL that returns a list of the cars with their most recent
registration number looks like? I just can't figure it.

--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to