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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:33:42+00:00 2026-05-25T01:33:42+00:00

I got two tables: CREATE TABLE IF NOT EXISTS `groups2rights` ( `groups2rights_group_id` int(11) NOT

  • 0

I got two tables:

CREATE TABLE IF NOT EXISTS `groups2rights` (
  `groups2rights_group_id` int(11) NOT NULL default '0',
  `groups2rights_right` int(11) NOT NULL default '0',
  PRIMARY KEY  (`groups2rights_group_id`,`groups2rights_right`),
  KEY `groups2rights_right` (`groups2rights_right`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `groups2rights` (`groups2rights_group_id`, `groups2rights_right`) VALUES (1, 35);

CREATE TABLE IF NOT EXISTS `rights` (
  `right` int(11) NOT NULL auto_increment,
  `right_name` varchar(255) default NULL,
  `description` text NOT NULL,
  `category` int(11) NOT NULL default '0',
  PRIMARY KEY  (`right`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=36 ;

INSERT INTO `rights` (`right`, `right_name`, `description`, `category`) VALUES
(33, 'admin_right_group_add', '', 100),
(34, 'admin_right_group_edit', '', 0),
(35, 'admin_right_group_delete', '', 0);

ALTER TABLE `groups2rights` ADD CONSTRAINT `groups2rights_ibfk_4` FOREIGN KEY (`groups2rights_right`) REFERENCES `rights` (`right`) ON DELETE CASCADE;

Now I tried to select all available Rights and also get if the group has it assigned, but somehow I’m missing some of the rights. Query:

SELECT r.*,g2r.groups2rights_group_id
FROM rights AS r
LEFT JOIN groups2rights AS g2r ON (g2r.groups2rights_right=r.right)
WHERE g2r.groups2rights_group_id=<<ID>> OR g2r.groups2rights_group_id IS NULL
ORDER BY r.category,r.right_name ASC

Any ideas?

Edit:
Updated the Code.

Expected Result be 3 Rows with 2 of them Havin a Null field and one having a value set.

  • 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-05-25T01:33:43+00:00Added an answer on May 25, 2026 at 1:33 am

    If you do

    SELECT r.*,g2r.group_id
    FROM rights AS r
    LEFT JOIN groups2rights AS g2r ON (g2r.right=r.right)
    WHERE g2r.group_id=<<#id>> OR g2r.group_id IS NULL
    ORDER BY r.category,r.right_name ASC
    

    You will not gets rows where g2r.group_id <> null and also g2r.group_id <> <<#id>>

    If you want to get all rows in rights and some of the rows in groups2rights you should do:

    SELECT r.*,g2r.group_id
    FROM rights AS r
    LEFT JOIN (SELECT * FROM groups2rights WHERE group_id=<<#id>>) AS g2r 
    ON (g2r.right=r.right) 
    ORDER BY r.category,r.right_name ASC
    

    This should work.

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

Sidebar

Related Questions

I got this two tables: CREATE TABLE `reservation` ( `id_reservation` int(11) PRIMARY KEY, `reserved_date`
I have got a problem with two tables: CREATE TABLE IF NOT EXISTS `addresses`
I want to create a table with Primary key referenced to Two columns of
I got two tables named Personnel and Department. **Personnel Table ;** PERSONNELID int ,
I have two tables linked by a foreign key. Example: CREATE TABLE one (id
I got two tables Product(Productname VARCHAR(10), Rating REAL) and Review(RatingID INT, Productname VARCHAR(10), Rating
I got two tables in my database: user and call. User exists of 3
I've got a table structure I'm not really certain of how to create the
The scenario I've got two tables with identical structure. TABLE [INFORMATION], [SYNC_INFORMATION] [ITEM] [nvarchar](255)
I've got two tables in my database: Articles and Tags The Tags tables consist

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.