Article View: bit.listserv.sqlinfo
Article #312Re: Intermediate SQL question
From: brayasam
Date: Thu, 21 Feb 2002 04:40
Date: Thu, 21 Feb 2002 04:40
73 lines
3439 bytes
3439 bytes
Just some tricks :) try this. SELECT min(Message) as Msgm, TSIMILAR_MESSAGE_TO_MESSAGE.ID, Count(TSIMILAR_MESSAGE_TO_MESSAGE.MESSAGE_ID) AS CountOfMESSAGE_ID FROM TSIMILAR_MESSAGE_TO_MESSAGE GROUP BY TSIMILAR_MESSAGE_TO_MESSAGE.ID HAVING (((Count(TSIMILAR_MESSAGE_TO_MESSAGE.ID))>1));" Hope this helps. B. Rayasam. "dsaf" <zxcv@gf.ll> wrote in message news:p7jc8.66438$Cg5.3892987@news1.calgary.shaw.ca... > I prefer leaving SQL to the gurus, but this is a small project, so I have > the joy of writing the entire app. > > > My problem > > I have two tables > > TMESSAGE > with fields > message_id, message > > and > TSIMILAR_MESSAGE_TO_MESSAGE > with fields > id, message_id > > TMESSAGE.message_id relates to both TSIMILAR_MESSAGE_TO_MESSAGE.message_id > and TSIMILAR_MESSAGE_TO_MESSAGE.id as a one to many relationship. > TSIMILAR_MESSAGE_TO_MESSAGE.message_id and TSIMILAR_MESSAGE_TO_MESSAGE.id > together make the primary key for their table. > > Now I want to group the similar messages to see which is the largest group > of similar messages. > This is easy: > > "SELECT TSIMILAR_MESSAGE_TO_MESSAGE.ID, > Count(TSIMILAR_MESSAGE_TO_MESSAGE.MESSAGE_ID) AS CountOfMESSAGE_ID > FROM TSIMILAR_MESSAGE_TO_MESSAGE > GROUP BY TSIMILAR_MESSAGE_TO_MESSAGE.ID > HAVING (((Count(TSIMILAR_MESSAGE_TO_MESSAGE.ID))>1));" > > This provides a table as follows > > message_id CountOfMESSAGE_ID > > 24 7 > 31 4 > 36 3 > > The problem is I also want the message returned in the query > (TMESSAGE.message). > In other words I would like a resultset that looks as follows: > > message message_id CountOfMESSAGE_ID > > I am a message 24 7 > I am a message too 31 4 > I am a message also 36 3 > > I'm sure it's fairly simple, but I just can't quite figure it out. Any help > would be most welcome. > > > >
Technical Details
Message-ID:
<uT_c8.10136$S01.527308@sccrnsc02>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.mathworks.com!wn3feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mailReferences:
<p7jc8.66438$Cg5.3892987@news1.calgary.shaw.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10fec3,dcbb12d615d54abb X-Google-Attributes: gid10fec3,public X-Google-Thread: 11355a,dcbb12d615d54abb X-Google-Attributes: gid11355a,public X-Google-Thread: 10de66,dcbb12d615d54abb X-Google-Attributes: gid10de66,public X-Google-Thread: 107d2f,dcbb12d615d54abb X-Google-Attributes: gid107d2f,public X-Google-ArrivalTime: 2002-02-20 20:41:03 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.mathworks.com!wn3feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail From: "brayasam" <brayasam@attbi.com> Newsgroups: bit.listserv.sqlinfo,borland.public.delphi.database.sqlservers,comp.databases.oracle,microsoft.public.sqlserver References: <p7jc8.66438$Cg5.3892987@news1.calgary.shaw.ca> Subject: Re: Intermediate SQL question Lines: 75 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: <uT_c8.10136$S01.527308@sccrnsc02> NNTP-Posting-Host: 12.237.40.124 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc02 1014266458 12.237.40.124 (Thu, 21 Feb 2002 04:40:58 GMT) NNTP-Posting-Date: Thu, 21 Feb 2002 04:40:58 GMT Organization: AT&T Broadband Date: Thu, 21 Feb 2002 04:40:59 GMT