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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

86 views 0 5
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