dHello can you help me with a query about ordering the topics by most recent posts? i mean that i want a topic to go on top when someone post on it. Here are the tables:
Discussion
- id_discution
- name
- id_category
- date
Comments
- id_comment
- id_user
- description
- type
- id_discussion
- date (timestamp)
here is my code but i get duplicates of topics but they are orderd good
select discussion.id_discution, discussion.name, discussion.id_category,
discussion.date, discussion.report, comments.id_comment, comments.id_pet_dem_des,
comments.date,comments.type
from discussion,comments
where discussion.id_discution=comments.id_discussion
AND type=3
order by comments.id_comment desc
GROUP BYthe discussion table’s primary key…Note: I don’t include any data from the
commentstable in theSELECTclause.This is because you only want each discussion to appear once, but each discussion can have many comments. You either have the discussion appear many times, and include the comments, or you don’t include the comments data in the results.
You could include aggregate values, such as
COUNT(*)to show how many comments there areMAX(comments.date)to show how recently the discussion was commented on, etc, etc.