Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with SELECT and JOIN please!

Author  Topic 

ChrisF79
Starting Member

1 Post

Posted - 2005-11-04 : 10:50:51
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!

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-04 : 11:20:26
LIMIT? Is this mySQL?

COUNT is going to come From and Aggregation function using GROUP BY

Read the link below to help us with details



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-05 : 00:36:20
Post your question at MySQL forum of www.Dbforums.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -