Forum Discussion

Myko_P's avatar
Myko_P
Expert
8 years ago

What is wrong with my LiQl query?

Hi!

I am trying to make component which can select and display all the users with "Moderator" role and one user with a specific username Myko_P. What am I doing wrong?

 

<#assign modId_request = rest("2.0","/search?q=" + "SELECT id FROM users WHERE rank.name = 'Moderator' AND login = 'Myko_P'"?url).data.items />

  • Myko_P-

     

    as ChiaraS mentioned it will only return one user as you have used AND . However, i have tried this query with OR as well, result was still only one user.

     

    Please user two query :

     For all the users who has Moderator role.

    <#assign modId_request = rest("2.0","/search?q=" + "SELECT id FROM users WHERE rank.name = 'Moderator'"?url).data.items />

    For the Myko_P

    <#assign modId_request = rest("2.0","/search?q=" + "SELECT id FROM users WHERE login = 'Myko_P'"?url).data.items />

     

    Combine the result of both query.

     

    Give kudos if you find my posts helpful or mark solution if it answers your query

    Tariq

     

4 Replies

  • Myko_P-

    Could you try this query and confirm your rank name?  You might be sending wrong rank name. This query worked fine for me.

    SELECT rank FROM users WHERE login = 'Myko_P'

    Also, login is a unique identifier, why do you need to pass the rank.name = 'Moderator' result would be same  even if you don't add rank.name = 'Moderator'.

     

    Give kudos if you find my posts helpful or mark solution if it answers your query

    Tariq

     

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)
    8 years ago

    Myko_P this call will only show the id of the user with nickname "Myko_P" if he has the rank "Moderator", since you're using an AND in the query. You would need to do 2 queries, one for the Moderator rank users and one for the specific user and manually combine the results (if that's the logic you need)

  • Myko_P's avatar
    Myko_P
    Expert
    8 years ago

    Thanks for help!

    I need to select all users with "Moderator" rank AND one user with specific username, who has no "Moderator" rank.

    Can I do this in one query?

    Actually this query is a part of the community component, which shows our community team: 4 moderators and 1 admin. But our community got more then 1 admin. So selecting by the rank or role will not work for me.

  • Myko_P-

     

    as ChiaraS mentioned it will only return one user as you have used AND . However, i have tried this query with OR as well, result was still only one user.

     

    Please user two query :

     For all the users who has Moderator role.

    <#assign modId_request = rest("2.0","/search?q=" + "SELECT id FROM users WHERE rank.name = 'Moderator'"?url).data.items />

    For the Myko_P

    <#assign modId_request = rest("2.0","/search?q=" + "SELECT id FROM users WHERE login = 'Myko_P'"?url).data.items />

     

    Combine the result of both query.

     

    Give kudos if you find my posts helpful or mark solution if it answers your query

    Tariq