Click to See Complete Forum and Search --> : SQL query with 2 tables


Rauldinho
01-09-2008, 10:03 PM
Hi, i'm a little bit rusty with SQL since i haven't used it for a while and i have this problem. I have 2 tables, A and B, A contains information about a parent and B the information about his children. Every children has an unique ID and also the ID of his/her parent.

What i want to do is to create a query that shows me all the data from a parent and also counts the number of children that he has. I thinks this involves using JOINs, i'm trying to remember.

Hope i made myself clear, thanks for any help i may get.

chazzy
01-10-2008, 05:01 AM
Ok...



select columns... from
table_a
join
table_b
on reference_column_in_table_a = reference_column_in_table_b


?

Rauldinho
01-10-2008, 09:37 AM
thanks for your answer, but this doesn't give me the number of children that a parent in table A has in table B.

chazzy
01-10-2008, 06:24 PM
so then put a count in by "columns..." and a group by parent_id.

potterd64
01-10-2008, 06:48 PM
select count(child_id) from
parent_table, child_table
where parent_table.parent_id = child_table.parent_id
group by parent_id