Article View: bit.listserv.sqlinfo
Article #314Re: Intermediate SQL question
From: David Bechtel
Date: Sat, 23 Feb 2002 14:19
Date: Sat, 23 Feb 2002 14:19
95 lines
4238 bytes
4238 bytes
Sorry to stick my nose in here, but isn't MIN(Message) a function to return the minimum value in the Message column? Assuming that Message is a number. Since this isn't the case, this won't do what he wanted. However, If your thought was to return the messages in length order based on what dsaf showed us, then you would want to calculate the length of the string Message and order the results by that value. Also, to get this reference to Message to work, you need to add TMESSAGE to the From clause and add a Where clause linking the two tables. Hope this helps, Dave Bechtel brayasam wrote: > 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:
<3C77A538.9DCACAC2@attbi.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!wn2feed!wn3feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc53.POSTED!not-for-mailReferences:
<p7jc8.66438$Cg5.3892987@news1.calgary.shaw.ca> <uT_c8.10136$S01.527308@sccrnsc02>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: 107d2f,dcbb12d615d54abb X-Google-Attributes: gid107d2f,public X-Google-Thread: 11355a,dcbb12d615d54abb X-Google-Attributes: gid11355a,public X-Google-Thread: 10de66,dcbb12d615d54abb X-Google-Attributes: gid10de66,public X-Google-ArrivalTime: 2002-02-23 06:19:16 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.cwix.com!wn2feed!wn3feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc53.POSTED!not-for-mail Message-ID: <3C77A538.9DCACAC2@attbi.com> From: David Bechtel <davidbechtel@attbi.com> X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: bit.listserv.sqlinfo,borland.public.delphi.database.sqlservers,comp.databases.oracle,microsoft.public.sqlserver Subject: Re: Intermediate SQL question References: <p7jc8.66438$Cg5.3892987@news1.calgary.shaw.ca> <uT_c8.10136$S01.527308@sccrnsc02> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 96 NNTP-Posting-Host: 12.245.62.238 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc53 1014473954 12.245.62.238 (Sat, 23 Feb 2002 14:19:14 GMT) NNTP-Posting-Date: Sat, 23 Feb 2002 14:19:14 GMT Organization: AT&T Broadband Date: Sat, 23 Feb 2002 14:19:14 GMT