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
 SQL Server Development (2000)
 Select and Group by.

Author  Topic 

TazMania
Yak Posting Veteran

63 Posts

Posted - 2005-01-13 : 05:44:07
Hi,

I have 2 tables

One called link.
LinkID,int
LinkDate,datetime
Linktext,varchar
Link,ntext
LinkCat,varchar
LinkHits,int

and the other LinkCat
LinkCatID,int
LinkCatDate,datetime
LinkCatText,varchar

I looking for a way to write a select clause something like this.

SELECT Link.LinkID,Link.LinkDate,Link.LinkText,Link.Link,Link.LinkCatID,Link.LinkHits,LinkCat.LinkCatID,LinkCat.LinkCatText FROM Link LEFT OUTER JOIN LinkCat ON Link.LinkCatID=LinkCat.LinkCatID GROUP BY Link.LinkCatID

But I can't it to work properly.

Any assistence would be much appreciated !

Best regards
Taz :)


Best regards
Taz

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2005-01-13 : 07:20:30
SELECT

Link.LinkID, Link.LinkDate, Link.LinkText, Link.Link, Link.LinkHits,

LinkCat.LinkCatID, LinkCat.LinkCatText

FROM Link LEFT OUTER JOIN LinkCat ON Link.LinkID=LinkCat.LinkCatID


--- GROUP BY Link.LinkCatID -- why "group by"?

and I don't see field LinkCatID in "left" table Link.
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2005-01-13 : 07:36:42
Thx for the reply :)

Wups.. my mistake LinkCat in table Link should be LinkCatID. :)

And the reason for group by is that the Link table can have several link under the same group, and instead of code this in asp, I just figured it would run much smoother if I would let the sql server handle this..

Data example from link table
LinkID - LinkDate - LinkText - Link - LinkCatID - LinkHits
1 - 13.01.05 - test1 link - http://www.test1.com - 1 - 0
2 - 10.01.05 - test2 link - http://www.test2.com - 1 - 0

Data example from LinkCat
LinkCatID - LinkCatDate - LinkCatText
1 - 09.01.05 - Test cat

Best regards
Taz
Go to Top of Page
   

- Advertisement -