Query to get active users ,groups from Database

Hi Team,

I require to fetch the details of active users from Database, which belong to different groups. I tried below query:

SELECT u.id AS UserId, user_name, lower_first_name, lower_last_name, parent_id AS GroupId, parent_name AS GroupName FROM cwd_user u LEFT JOIN cwd_membership m ON u.ID=m.child_id where u.active='1' ORDER BY parent_id ;

and

SELECT u.id AS UserId, u.active,user_name, lower_first_name, lower_last_name, parent_id AS GroupId, parent_name AS GroupName FROM cwd_user u LEFT JOIN cwd_membership m ON u.ID=m.child_id ORDER BY parent_id ;

But the result is not showing only active users, it shows active and inactive both,

Can you please help me with exact query?


I raised a query with Atlassian support but they are saying they do not support custom query.


Please suggest.


Nidhi

2 answers

Yes, the SQL in there is unreadable as well.  Can you tell us what the simple "show us active users" does as compared with "show all users"?

0 vote

Correct, they do not support any (ab)use of the database.

Your use of "as" confuses the query and I can't read it clearly enough to see what it's doing (I know as is useful, but plain SQL without it is far more readable when you're trying to work out what a query is doing, as it remains more like the way a human would phrase a question)

Select * from cwd_user where active = '1' ;

Should list users who are active.  In the sense that you have not clicked on the "deactivate" option for them in the user management.  Start with that query - does it do what you expect?  The list is shorter than when you use just "select * from cwd_user"?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

409 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you