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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:25:19+00:00 2026-05-28T02:25:19+00:00

I have three tables I would like to join to pull off a MySQL

  • 0

I have three tables I would like to join to pull off a MySQL Query that will check to see if a user has access to download photo. Each photo has its own access rights which can be one of the following.

Level one – any user can download the photo.
Level two – only users who have access can download the photo.

Table 1: FILES

FILE_ID is AUTO_INCREMENT
USER_ID is the identifier of the user that owns the file.
FILE_NAME is just the name of the photo.
FILE_ACCESS is the access rights to the 2 levels noted above.

FILE_ID | USER_ID | FILE_NAME | FILE_ACCESS
1 | 3 | 1279141923.jpg | 1
2 | 3 | 1279141925.jpg | 1
3 | 3 | 1279141927.jpg | 2
4 | 4 | 1279141929.jpg | 1
5 | 4 | 1279141931.jpg | 2
6 | 3 | 1279141933.jpg | 2

Table 2: USERS

USER_ID is AUTO_INCREMENT
USER_NAME is just the name of the file owner.

USER_ID | USER_NAME
1 | jack
2 | jill
3 | john
4 | mike

Table 3: ACCESS

ACCESS_ID is AUTO_INCREMENT
USER_ID is the identifier of the user that owns the file.
ALLOW_ID is the identifier of the user that has access all the file uploaded by user.

ACCESS_ID | USER_ID | ALLOW_ID
1 | 3 | 1
2 | 3 | 4

User Jack has access to download photos 1279141923.jpg, 1279141925.jpg and 1279141927.jpg that John has uploaded while Jill only has access to 1279141923.jpg and 1279141925.jpg

Jack gets access to all three as files 1 and 2 have access level one while he also gets access to download file 3 seeing that John has given him full access to all files uploaded by John.

SELECT a.file_name, b.user_name FROM files AS a
  JOIN users AS b ON a.user_id = b.user_id
  WHERE a.file_access = '1'

This MySQL Query gives me the following when Jill is signed in.

1279141923.jpg, john (owner name)
1279141925.jpg, john
1279141929.jpg, mike

I am now looking to introduce the ACCESS table into this Query, so that if Jill is signed in she is displayed with the same results as above will if Jack was signed he would get the following results.

1279141923.jpg, john (owner name)
1279141925.jpg, john
1279141927.jpg, john
1279141929.jpg, mike
1279141933.jpg, john

I hope I explain this right, as I sure need help with the last portion. I am not quite sure how to add this to the current Query. I can do it using multiple queries – but I prefer if possible would like to leave it as one.

  • 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-28T02:25:20+00:00Added an answer on May 28, 2026 at 2:25 am
    SELECT DISTINCT(F.id), F.filename
    FROM files F, ACCESS A
    WHERE F.flie_access=1
    OR (F.user_id=2)
    OR (F.user_id = A.user_id AND A.allow_id=2);
    

    So, you can access the file if it is:

    level 1 (ie public)
    or you are the owner
    or you have a matching access entry in the ‘ACCESS’ table.

    You seem to have granted access to ALL a users files to another user, you might want to consider a “USER_ACCESS” and a “FILE_ACCESS” table to grant other people access to either all your files or just a specfific file.

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

Sidebar

Related Questions

We have three tables that we would like to query to find out the
I have the following three tables: alt text http://img16.imageshack.us/img16/5499/linqtosqlquery.jpg With LinqToSql I would like
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have three tables. This query will write down the right answer (x-lines for
I have two tables which I would like to join by ID field. I
Lets say that I have a database structure with three tables that look like
I have three tables (people, clients_people, clients) that would be joined using SELECT *
I have three tables: users, courses and documents. I would like to upload documents
I have three tables in MySQL that are related, yet not technically linked to
I have a list that is pulled from three tables, Department, Type and User.

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.