Select Users from Alfresco Database

The following SQL (designed for MySQL as it uses group_concat) pulls out a list of users from the Alfresco database by searching for the appropriate nodes in the Alfresco node table and pulling user node properties including username, firstName, lastName and email address.

select
    node_id,
    group_concat(string_value)
from (
    select
        node_id,
        qname_id,
        (select local_name from alf_qname where id = qname_id) as qname_type,
        string_value
    from alf_node_properties
    where node_id in (
        select id from alf_node 
        where type_qname_id = (
            select id from alf_qname where local_name = 'person'
        )
        and qname_id in (
            select id
            from  alf_qname 
            where local_name in (
                'username',
                'firstName',
                'lastName',
                'email'     
            )
        )
    )
) alf_users
group by node_id;