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 8670051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:37:25+00:00 2026-06-12T18:37:25+00:00

I have two tables: nets_permissions user_id INT NOT NULL, network_id BIGINT UNSIGNED NOT NULL,

  • 0

I have two tables:

nets_permissions

    user_id INT NOT NULL,
    network_id BIGINT UNSIGNED NOT NULL,
    perm INT(3) NOT NULL,
    PRIMARY KEY(user_id, network_id)


devices_permissions

    user_id INT NOT NULL,
    network_id BIGINT UNSIGNED NOT NULL,
    device_id INT UNSIGNED NOT NULL,
    perm INT(3) NOT NULL,
    PRIMARY KEY(user_id, network_id, device_id),

The nets_permissions table has permissions for each user. A user can have a different perm values: 1 for read permission, 2 for write permission, 4 for read+commands permission. The net admin have a perm value of 3.

Same thing for the second table, but this time for the devices that are in the specific net. The users are added to this table when the admin of the net and devices give them a permission. But the admin of the net is not registered in this table. He is only in the nets_permission table with perm=3.

I have to create a query that select the permission of the current user in an handler of Tornado Web Server. The code is in this form:

# Retrieve the current user 
    usr = self.get_current_user()
    usr_id = usr['id']
    self.lock_tables("read", ['nets_permissions as n, devices_permissions as d'])
    usrperm = self.db.query("SELECT * FROM nets_permissions as n 
         LEFT OUTER JOIN devices_permissions as d 
              ON n.network_id = d.network_id WHERE d.user_id=%s 
                 AND d.device_id=%s", 
         int(usr_id), sens.id);
    self.unlock_tables()

In usr_id I retrieve is the id of the current user.

The current user can be the admin of the net (so he is only in the table nets_permissions with perm=3) or a user with some permission on the specific device (so he is only in the devices_permissions table with some value for perm).

In the query result ‘userperm’ I would use an integer to compare after in the html page with a permission value and to show or not something to the user.

Sorry for my English but is difficult explain for me the problem. I don’t know I can structure the query to obtain this result I want.

Thank you very much 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-12T18:37:26+00:00Added an answer on June 12, 2026 at 6:37 pm
    SELECT distinct 'net', network_id, perm
    FROM nets_permissions n
    JOIN devices_permissions d
    USING (user_id, network_id)
    WHERE n.user_id = '%s'
    AND d.device_id = '%s'
    
    UNION ALL
    
    SELECT 'device', network_id, perm
    FROM devices_permissions
    WHERE user_id = '%s'
    AND device_id = '%s'
    

    However, it looks like there’s a problem with your data model. If a device has no users with permissions to the device, there won’t be a row in devices_permissions, so we won’t be able to find its network_id. You need to normalize this better: there should be a device_network table to relate them.

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

Sidebar

Related Questions

I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have two tables: CREATE TABLE tblEatables ( `EatId` int UNSIGNED PRIMARY AUTO_INCREMENT, `Fruits`
I have two tables user table user_id | name | 1 | peter |
I have two tables, Table_1 and Table_2 . Table_1 has columns PK (autoincrementing int
I have two tables in which the second table has a foreign key which
I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions
I have two tables with a foreign key constraint how can I delete rows
i have two tables item_tb | item_id | user_id | --------------------- user_tb | user_id
I have two tables images2 and image_data So the goal is to have 1
I have two tables 1.Products prod_id prod_name 1 honda 2 hero 3 marcedes 4

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.