Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql que

Status
Not open for further replies.

habesha

Programmer
Oct 30, 2006
68
0
0
US
I have a parent and child table
for each record in the parent table there are multiple corresponding records in the child table

I want to query out the latest data from the child table for each record in the parent table
how ca i do that

remember the parent and child table have a foreign key relationship

thanks
 
remember the parent and child table have a foreign key relationship

They do? How am I supposed to know that, much less remember it when you haven't shown us what your schema looks like or provided sample data?

-SQLBill

Posting advice: FAQ481-4875
 
parent table

id col1
1 xy
2 xz

child table

id1 id col1
1 1 de
2 1 fr
3 2 gh
4 1 vf
5 2 cg


id foreign key

get the latest entry in the child table for each id in the parent table

thanks
 
if what you mean by the latest entry is the record wit the max id then
Code:
select * from 
[child table]
inner join(
select max(id1) mid
from child table
group by id)dt 
on dt.mid=[child table].id1
 
Thank you very much I appreciate that

now I want to write a query that for each record in the parent tables I want to get the corresponding record in the child table in a single column

eg id 1 has in parent table has three corresponding record in child table my output should look like

id col3
1 de, fr, vf
2 gh, cg

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top