Click to See Complete Forum and Search --> : My sql query join


spsarolkar
02-12-2009, 11:29 AM
I am creating a forum website i have two tables as follows: -
table topic
login(primary key)
entrytime(primary key)
category
topic_name
table reply
reply_login(primary key)
reply_entrytime(primary key)
topic_login
topic_entrytime
reply_body
foreign key(topic_login,topic_entrytime)references topic(login,entrytime)

Now what i want to do is calculate no of replies for each category, if possible with single query , i have very rough knowlege of join
i am using mysql 5.x and php 5.2

spsarolkar
02-12-2009, 12:37 PM
please somebody help:confused::confused:

chazzy
02-12-2009, 05:46 PM
please repost your table structure with single primary keys (auto inc). don't use composite keys in this case


select count(*),tt.category from table_topic tt inner join table_reply tr on tt(topic_login,topic_entrytime) = tr(topic_login,topic_entrytime) group by tt.category;

spsarolkar
02-13-2009, 03:26 AM
Thanks very much for your query, i used
select count(*),tt.category from table_topic tt inner join table_reply tr on tt.topic_login=tr.topic_login and tt.topic_entrytime=tr.topic_entrytime group by tt.category;:D:D:D:D:D:D:D