Sign in to follow this  
Followers 0
Jochem

SQLite group_concat order by

3 posts in this topic

#1 ·  Posted (edited)

Is there something like group_concat(......ODER BY..........)

I have a querie and want to order also the grouped values alphabatical

SELECT ADgroupname, group_concat((SUBSTR(USfullname, 1,LENGTH(USfullname)-6)) || ' ,' , '  ' ) "users"
FROM AD_group_members
    JOIN users ON ADGMUsId = usid AND USstatus IS 'enabled'
    JOIN AD_Groups ON ADGMGroupId = ADgroupid     
    GROUP BY ADgroupname   
    ORDER BY ADgroupname
Edited by Jochem

Share this post


Link to post
Share on other sites



It's hard to advise without seeing the DB schema.

Can you post it by either using sqlite3.exe (recent version) and using the .fullschema command or by selecting the DB (not one of its table) in SQLite Expert and hitting the DDL tab (preferred method)?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

these are the three tables I am using:

CREATE TABLE [AD_group_members] (
  [ADGMid] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT COLLATE NOCASE, 
  [ADGMUsId] INTEGER(25) NOT NULL CONSTRAINT [fkUSid] REFERENCES [Users]([USid]) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED COLLATE NOCASE, 
  [ADGMGroupId] INTEGER(25) NOT NULL CONSTRAINT [fkGroupId] REFERENCES [AD_Groups]([ADgroupid]) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED COLLATE NOCASE);

CREATE TABLE [AD_Groups] (
  [ADgroupid] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  [ADgroupname] CHAR NOT NULL UNIQUE COLLATE NOCASE);

CREATE TABLE [Users] (
  [USid] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  [USname] CHAR(50) NOT NULL UNIQUE COLLATE NOCASE, 
  [USfirstname] CHAR(25) COLLATE NOCASE, 
  [USfamilyname] CHAR(50) COLLATE NOCASE, 
  [USstatus] CHAR(25) COLLATE NOCASE, 
  [USfullname] CHAR(50) COLLATE NOCASE, 
  [USSite] CHAR(25) COLLATE NOCASE DEFAULT unknown);



oops I forgot one table; added it now, the hole db is around 1000 lines. Maybe not a good idea to post here?

Edited by Jochem

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0