🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #851

Re: Help with SQL statement

#851
From: Viatcheslav V. Vassiliev
Date: Tue, 21 Jun 2005 07:36
59 lines
2419 bytes
This depends on DBMS you are using. On MS SQL Server you may write

insert into TblTemp (text)
select text from TblSource
group by text
order by max(id)

Note max(id) - there may be some id's for unique text, so you should use 
aggregate function - max, min, avg etc.

This may or may not work on DBMS other than MS SQL Server.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 + 
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Vladimir Stefanovic" <antivari@po.sbb.co.yu> �������/�������� � �������� 
���������: news:42b71709@newsgroups.borland.com...
>I have a single table with this imaginary format:
>
> ID     TEXT
> ------------
> 2      AAAA
> 5      BBBBB
> 4      CCCC
> 3      AAAA
> 1      BBBBB
>
> ID is uniq
> TEXT is not unique
>
> I want to extract into NEW Table
>
>   AAAA
>   BBBB
>   CCCC
>
> somehow like
>
>      "INSERT INTO TblTmp (Text)\n"
>      "SELECT Text\n"
>      "FROM TblSource\n"
>      "GROUP BY Text";
>
> ...but I want them ALSO to be sorted by ID, and I doesn't
> know how to involve ORDER into this...
>
>
>
>
>
> -- 
> Best regards,
> Vladimir Stefanovic
> 
Technical Details
Message-ID: <42b7c364$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <42b71709@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,d883a75625ee119f
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <42b71709@newsgroups.borland.com>
Subject: Re: Help with SQL statement
Date: Tue, 21 Jun 2005 11:36:06 +0400
Lines: 61
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 85.93.138.132
Message-ID: <42b7c364$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1119339364 85.93.138.132 (21 Jun 2005 00:36:04 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail