House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  SQL

DISTINCT clause on certain columns only

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Hi,
Claude_Schnéegans
12/08/10 11:51 A
Hey Claude,
Bryan Stevenson
12/08/10 12:06 P
This should do it:
DK
12/08/10 01:18 P
Sorry, this should be:
DK
12/08/10 01:26 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude_Schnéegans
12/08/2010 11:51 AM

Hi, It happens often that I'd need to have a DISTINCT clause applied to some columns only, instead of the whole row. Example: I have a request of rejected messages with a date-time column and the addess in another one. Sometimes, the sever attempted to send the messages many times to the same address. I'm not interest of having the time for every attempts, only the first one. Ex: SELECT DISTINCT errorTime, address, errorMess What I need who be kind of: SELECT DISTINCT(address, errorMess) errorTime, address, errorMess Any idea on how to do this in plain SQL ? (The database is Access)

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
12/08/2010 12:06 PM

Hey Claude, It sounds like you want a single record when an address has multiple attempts.....so that is what I'm basing my assumptions on.... 1) I don't think this is possible. You can get just one record per address, but you'd have to loop over that output and lookup the error time and messages for each address (not efficient but would get you what I think you're after). 2) You could play with the "GROUP BY" clause, but you'll still end up with a record for every time/message combo for a given address SELECT address, errorMess, errorTime GROUP BY address, errorMess, errorTime If you find a solution...be sure to post it ;-) Cheers On Wed, 2010-12-08 at 11:51 -0500, =?ISO-8859-1?Q?Claude_Schn=E9egans wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
George Gallen
12/08/2010 01:08 PM

What if you used a sub query in place of the field? and had that subquery just be a DISTICT selection. George ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
DK
12/08/2010 01:18 PM

This should do it: SELECT address, errorMess, MIN(errorTime) as firstErrorTime, MAX(address) --   or MIN(address) FROM table WHERE .... GROUP BY address, errorMess Dharmendar Kumar http://www.realmagnet.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
DK
12/08/2010 01:26 PM

Sorry, this should be: SELECT address, errorMess, MIN(errorTime) as firstErrorTime FROM table WHERE .... GROUP BY address, errorMess I didn't realize you already had 'address' in you main select. Dharmendar Kumar http://www.realmagnet.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude_Schnéegans
12/08/2010 12:13 PM

>>It sounds like you want a single record when an address has multiple attempts. Exactly. Some errors are permanent and the server won't retry, some are not and the server will retry many time. In that case I'm only interested in the time of the first attempt, since it corresponds the time the application sent all messages.


<< Previous Thread Today's Threads Next Thread >>

Search sql

June 19, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
             1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30             

Designer, Developer and mobile workflow conference