Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:09:35+00:00 2026-06-12T06:09:35+00:00

I have this query: SELECT DISTINCT u.id, u.name, n.network_id, n.perm FROM users as u

  • 0

I have this query:

SELECT  DISTINCT 
        u.id, 
        u.name, 
        n.network_id, 
        n.perm 
FROM    users as u RIGHT OUTER JOIN 
        nets_permissions as n ON u.id = n.user_id AND n.perm<> 3 
WHERE   u.id!=3

and the result is this:

id  name    network_id  perm
1   Luca Niccolini  9124823324095   1
2   Irene Pippo 9124823324095   0
2   Irene Pippo 1234567812345678124 1

Now I want that the result of the query is:

id  name    network_id  perm
1   Luca Niccolini  9124823324095   1
2   Irene Pippo 9124823324095   0

Infact I want to grant the permission on a net to some users. This users can already have a permission on the net, but also on other nets. So in this case the user Luca has only the permission on the net 9124823324095, but the user Irene has two permissions, on two different nets. I want grant the permissions on the net 9124823324095, so I don’t want the third record.

But I can’t filter with the net id, because i could have a user that have a permission on other nets, but not on my net.

In other words I would that
-for users that have two or more record in the query, I can take only the record of my net
-for users with only a record I can take that record.

It’s difficult to explain. Thank you for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:09:37+00:00Added an answer on June 12, 2026 at 6:09 am

    The following code works in most dialects of SQL:

    select id, name, network_id, perm
    from (select t.*, count(*) over (partition by u.id) as NumRowsForUser
          from (SELECT  DISTINCT u.id, u.name, n.network_id, n.perm 
                FROM    users as u RIGHT OUTER JOIN 
                        nets_permissions as n ON u.id = n.user_id AND n.perm<> 3 
                WHERE   u.id!=3
               ) t
         ) t
    where NumRowsForUser > 1 and network_id = '9124823324095' or
          NumRowsForUser = 1
    

    Have you considered the case where there are multiple permissions on networks, but none are for your network? These are excluded by your conditions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: user = self.db.query(SELECT DISTINCT u.id, u.name, n.network_id, n.perm \ FROM
I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO
I have this query: SELECT DISTINCT phone, department FROM `users` WHERE ((SUBSTRING(phone,1,3) = '399')
I have the following query: SELECT wm_concat(DISTINCT NAME) as Methods FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS
I have this query: select distinct id,name from table1 For a given ID, the
I have this query select distinct Name,ID from tbl_abc where Name like '%william jam%'
I have this query... SELECT Distinct([TargetAttributeID]) FROM (SELECT distinct att1.intAttributeID as [TargetAttributeID] FROM AST_tblAttributes
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I have this query: select top(2) property_id_ref ,image_file ,property_name from property_master a inner join
In SQL Server, I have this query SELECT DISTINCT City FROM Person.Address But this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.