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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:07:57+00:00 2026-05-16T07:07:57+00:00

I have table called page which represents every single page in my website. page_id

  • 0

I have table called page which represents every single page in my website.

page_id | page_subject | page_path
----------------------------------
1       | Foo          | /Foo
2       | Bar          | /Bar

I also have table called group:

group_id | group_name
---------------------
1        | Users
2        | Admins

Goal: how to define access to every page for single group?
I did create another table – page_group:

page_group | group_id
---------------------
1          | 1
1          | 2

Table contains groups that have access to page (page_group).

I wrote function:

CREATE FUNCTION `PAGE_ACCESS`(`pageId` INT, `groupId` MEDIUMINT)
BEGIN
   RETURN IF((SELECT COUNT(*) FROM `page_group` WHERE page_id = pageId AND group_id = groupId) > TRUE, FALSE);
END;

Now I can do something like that:

SELECT * 
FROM page 
WHERE <conditions> AND PAGE_ACCESS(page_id, <group_id>)

…which returns pages that I should have access to.

Works fine but seems to be slow with with rows > 100,000
How would you do that? Would you do that in a different way?

  • 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-16T07:07:57+00:00Added an answer on May 16, 2026 at 7:07 am

    try:

    SELECT * 
    from Page p
    WHERE EXISTS (SELECT 1 from page_group pg join group g 
                  on (pg.group_id = g.groupidId)
                  WHERE g.group_id = <groupId>
                    AND p.page_id = pg.page_id)
    

    Also you can try (just realized that groups table does not required):

    SELECT * 
    from Page p
    WHERE p.page_id IN (Select page_id
                        from page_group pg
                        WHERE pg.group_id = <group_id>)
    

    or even:

    SELECT p.* 
    from Page p JOIN page_group pg ON (p.page_id = pg.page_id)
    WHERE pg.group_id = <group_id>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$value = 'http://www.mydomain.com/this-is-page-one' I have a field in my mysql table called urls which
I have a table called ApprovalTasks... Approvals has a status column I also have
I have a table called BlogPost which has a 1-to-many relationship with the Comment
i have a table called category in which i have main category ids and
Suppose I have a table called Companies that has a DepartmentID column. There's also
Say I have a table called xml that stores XML files in a single
I have a database table called Posts which stores all the information regarding an
I have a PHP page which generates an HTML table. At the bottom of
I have a table called ticket in which I want to swap two rows
I have a table called OffDays, where weekends and holiday dates are kept. I

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.