Welcome Guest, Not a member yet? Register   Sign In
Help Counting the comments from a table
#2

[eluser]mddd[/eluser]
You need to GROUP BY the relevant id. That is the hotel id, or the hotel data id, depending on how your tables work exactly. Anyway, do the grouping on the thing that identifies the group of comments you want to count. Then use COUNT to count the comments per group.

A simplied version: if you had only a table of hotels and a table of comments:
Code:
SELECT hotels.*, COUNT(comments.id) AS num_comments
FROM hotels
JOIN comments on comments.hotel_id = hotels.id


Messages In This Thread
Help Counting the comments from a table - by El Forum - 07-26-2010, 09:34 PM
Help Counting the comments from a table - by El Forum - 07-27-2010, 12:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB