Thank a lot David!
It worked.
This is exatcly sql statement that I want to have.
Once again thanks a ton David,
JP




________________________________
From: David Baird <dhba...@gmail.com>
To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
Sent: Tuesday, February 17, 2009 10:22:22 PM
Subject: Re: [sqlite] sql statement to concatinate two rows.

On Tue, Feb 17, 2009 at 11:16 PM, Joanne Pham <joannekp...@yahoo.com> wrote:
> Hi All,
> I have the select statement as below
> sqlite> select remoteId, hostName , remoteWXType from remoteWXTable order by 
> hostName;
> and the output  is below:
>
> 1|HostName1-T432|2
> 2|HostName2-T421|2
> 3|HostName3-XP|2
> 4|HostName3-XP|2
>
> But I would like the sql statement to return as below:
> (HostName3 has two remoteId so I want to return as one row but two different 
> remoteId as below)
> 1|HostName1-T432|2
> 2|HostName2-T421|2
> 3,4|HostName3-XP|2
> Can you please help to change the sql statement to return the above result 
> set.
> Thanks,
> JP
>

No problem...

SELECT group_concat(remoteId, ','), hostName, remoteWXType
    FROM remoteWXTable
    GROUP BY hostName; -- or remoteWXType ...?

I think group_concat is only supported in moderately recent versions
of sqlite3, so make sure to not be using something 1 or 2 years old.

-David
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



      
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to