MySQL- How to get user information and also their groups

Bernhard Riegler March 17, 2016

Hey,

I would need a MySql query where I get all my users (name,username,email,groups) from the JIRA Internal Directory.

 

With this query I get all the user information except the groups. But I would need the groups too.

select * from cwd_user where directory_id = 1
THX smile

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 17, 2016

Join cwd_user on to cwd_membership

Bernhard Riegler March 17, 2016

@Nic Brough [Adaptavist]Thx for your fast answer. I tried following query:

 

SELECT *

FROM cwd_user AS cu1

JOIN cwd_user AS cu2

  ON cwd_membership  

WHERE directory_id = 1;

 

Now I get the error "Column 'directory_id' in where clause is ambiguous".

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 17, 2016

Ah, sorry, I should have said - it needs to be joined on lower_child_name = username

Bernhard Riegler March 18, 2016

I still get the same error if I run this query:

SELECT *

FROM cwd_user AS cu1

JOIN cwd_user AS cu2

  ON cwd_membership

  AND lower_child_name = username   

WHERE directory_id = 1;

 

Did I forget something in my query?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 18, 2016

Simplify the SQL and make it explicit.  (The "as" phrase is the bane of SQL readability.  It's great when you're an expert DBA and no-one else has to understand what you're doing, but for most of us, it really just makes it all harder to read)

The most simple and precise form of this query is

Select * from cwd_user join cwd_membership on cwd_membership.lower_child_name = cwd_user.username

To limit the directory, add

where cwd_user.directory_id = 1

Bernhard Riegler March 18, 2016

Hey Nic Brough,

I'm sorry for it and no I'm not an expert DBA.

thx again for your help but now I get another error.

"ERROR 1054 (42S22): Unknown column 'cwd_user.username' in 'on clause'"

Do you have any idea whats the problem here?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 18, 2016

Yes, the problem is that I was looking at the wrong system.

Please replace it with cwd_user.lower_user_name

Sorry!

Bernhard Riegler March 22, 2016

Ahh that's great, now it works. Lovely! Many Thx!

Suggest an answer

Log in or Sign up to answer