🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #913

Re: SELECT MIN

#913
From: Maxim Shiryaev
Date: Thu, 19 Apr 2007 08:04
33 lines
1992 bytes
If you have only one DATE2 for each CLIENTID than you should use aggregate
on DATE2 as well:

select CLEINTID, min(DATE1), min(DATE2)
from yourtable
group by CLEINTID

By the way, it means your database is not normalized enough in this case.

If there are different DATE2 values for each CLIENTID than you can do
something like this

select CLIENTID, DATE2,
  (select min(yt2.DATE1) from yourtable yt2 where yt2.CLIENTID -
yt1.CLIENTID)
from yourtable yt1

Maxim.

"aleplgr" <aleplgr@yahoo.es> �������/�������� � �������� ���������:
news:4625f0e8@newsgroups.borland.com...
>
> Hi! I have a 3 columns table: CLIENTID DATE1 DATE2
> for each CLIENTID can be more than one DATE1 so I have to select the MIN.
Just doing this works fine:
> SELECT MIN (DATE1)
> from mytable
> group by CLIENTID
>
> Now I need also to show DATE2 in the result table, if I include it in the
SELECT I need to include  it in the GROUP BY but if I do that I don't get
the MIN(DATE1)for each CLIENTID: it returns all of them..
>
Technical Details
Message-ID: <4627224c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4625f0e8@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,ef167041b2966043
X-Google-Attributes: gid114a0e,public
X-Google-Language: ENGLISH,ASCII
From: "Maxim Shiryaev" <MaximShiryaev@gmail.com>
Newsgroups: borland.public.interbase.sql
References: <4625f0e8@newsgroups.borland.com>
Subject: Re: SELECT MIN 
Date: Thu, 19 Apr 2007 12:04:09 +0400
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 213.234.197.62
Message-ID: <4627224c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1176969804 213.234.197.62 (19 Apr 2007 01:03:24 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail