Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Most recent record in a related table
Thu, Apr 20 2006 2:39 PMPermanent Link

Geoff
At first I thought this would be easy, but I haven't been able to figure it out.

I have 2 Tables "sizing_details" and "returns" as follows:

sizing_details
--------------
id | orderid | name

1 | 10 | Leo
2 | 10 | Kai
3 | 10 | Elo
4 | 11 | Ann

returns
-------
sizing_details_id | reasonsCode | date_returned

1 | 3 | 01/01/2006
1 | 1 | 04/10/2006
2 | 4 | 02/02/2006
4 | 2 | 12/24/2005
2 | 2 | 03/03/2006


In my result for "orderid = 10", I would expect to see this:


id | orderid | name | reasonsCode | date_returned

1 | 10 | Leo | 1 | 04/10/2006
2 | 10 | Kai | 2 | 03/03/2006
3 | 10 | Elo | NULL | NULL

I've been working on this for a while, and haven't been able to solve it. Any help would
be greatly appreciated.

Thanks,
Geoff
Thu, Apr 20 2006 6:05 PMPermanent Link

Steve Forbes

Team Elevate Team Elevate

Hi Geoff,

Try this ..

SELECT
 sd.id,
 sd.orderid,
 sd.name,
 r.date_returned
FROM sizing_details sd
 LEFT JOIN returns r ON sd.id = r.sizing_details_id
ORDER BY r.date_returned DESC

--
Best regards

Steve

"Geoff" <gjukema@vu-ware.com> wrote in message
news:6ADEDCBE-696A-4742-954B-E207D5292391@news.elevatesoft.com...
> At first I thought this would be easy, but I haven't been able to figure
> it out.
>
> I have 2 Tables "sizing_details" and "returns" as follows:
>
> sizing_details
> --------------
> id | orderid | name
>
> 1 | 10 | Leo
> 2 | 10 | Kai
> 3 | 10 | Elo
> 4 | 11 | Ann
>
> returns
> -------
> sizing_details_id | reasonsCode | date_returned
>
> 1 | 3 | 01/01/2006
> 1 | 1 | 04/10/2006
> 2 | 4 | 02/02/2006
> 4 | 2 | 12/24/2005
> 2 | 2 | 03/03/2006
>
>
> In my result for "orderid = 10", I would expect to see this:
>
>
> id | orderid | name | reasonsCode | date_returned
>
> 1 | 10 | Leo | 1 | 04/10/2006
> 2 | 10 | Kai | 2 | 03/03/2006
> 3 | 10 | Elo | NULL | NULL
>
> I've been working on this for a while, and haven't been able to solve it.
> Any help would
> be greatly appreciated.
>
> Thanks,
> Geoff
>

Image