April 2, 2009 at 2:34 pm
I have two tables.
This is the first:
id date pay
-- -------- ---------
c 01/01/08 234.00
e 12/01/08 1234.29
a 18/01/08 529.00
y 21/01/08 612.00
p 10/02/08 19.90
x 11/02/08 35.78
e 21/02/08 84.23
c 03/03/08 67.28
p 16/03/08 900.00
a 11/04/08 5000.00
f 14/04/08 291.00
q 21/04/08 4822.72
w 30/04/08 84.65
i 03/05/08 1000.00
u 21/05/08 2900.50
t 22/05/08 451.20
o 25/05/08 73.30
p 01/06/08 43.34
w 07/06/08 6200.00
a 10/06/08 780.00
c 11/07/08 528.00
d 21/07/08 901.23
q 22/07/08 692.00
t 25/07/08 490.12
f 30/07/08 927.00
h 01/08/08 67.31
r 08/08/08 929.00
w 11/08/08 111.00
i 14/08/08 956.00
p 18/08/08 234.61
z 22/08/08 333.33
d 29/08/08 84.90
f 30/08/08 39.20
. . .
. . .
. . .
This is the second table:
id
--
d
m
w
q
a
k
o
e
c
y
p
I need build a query to get the last transaction
from first table for each id in sencond table.
Example:
id date pay
-- -------- ---------
d 29/08/08 84.90
m null null
w 11/08/08 111.00
q 22/07/08 692.00
a 10/06/08 780.00
k null null
o 25/05/08 73.30
e 21/02/08 84.23
c 11/07/08 528.00
y 21/01/08 612.00
p 18/08/08 234.61
Help me please ....
April 2, 2009 at 3:00 pm
Like this:
Select * From first F1
Where Date IN (Select MAX(Date)
From first F2
Where F2.id = F1.id
And F2.id IN (Select id From second) )
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
April 2, 2009 at 5:54 pm
thanks ....
April 2, 2009 at 6:39 pm
Glad I could help.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply