MySQL Forums
Forum List  »  InnoDB

Help needed on a small SELECT/JOIN statement
Posted by: Chris Farrugia
Date: November 04, 2005 10:23AM

Greetings,

I am very new to SQL and I need help with a select statement. I have two tables:

articles
--------
id
title
summary
dateposted

views
-----
ip
id
type

I want to select 10 article summaries per page, shown in descending order, with the number of times that article has been viewed. So far I have:

SELECT articles.id, articles.title, articles.summary, articles.dateposted
FROM articles
ORDER BY articles.dateposted DESC
LIMIT 0,10

That works fine to show me the articles the way I want. However, how do I add the count of the number of times that article has been viewed? I'm guessing it is a join, and I'm guessing there will be a statement in there that says WHERE (articles.id = views.id AND views.type = "article") but that is merely a guess.

Could anybody please help me clear this up? Thanks in advance for any guidance you could provide!

Options: ReplyQuote


Subject
Views
Written By
Posted
Help needed on a small SELECT/JOIN statement
2527
November 04, 2005 10:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.