Note that there are some explanatory texts on larger screens.

plurals
  1. POJoin three Tables to create an Access Granted List
    primarykey
    data
    text
    <p>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.</p> <p><strong>Level one</strong> - any user can download the photo.<br/> <strong>Level two</strong> - only users who have access can download the photo.</p> <p>Table 1: FILES</p> <pre><code>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 </code></pre> <p>Table 2: USERS</p> <pre><code>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 </code></pre> <p>Table 3: ACCESS</p> <pre><code>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 </code></pre> <p>User Jack has access to download photos <code>1279141923.jpg</code>, <code>1279141925.jpg</code> and <code>1279141927.jpg</code> that John has uploaded while Jill only has access to <code>1279141923.jpg</code> and <code>1279141925.jpg</code></p> <p>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.</p> <pre><code>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' </code></pre> <p>This MySQL Query gives me the following when Jill is signed in.</p> <pre><code>1279141923.jpg, john (owner name) 1279141925.jpg, john 1279141929.jpg, mike </code></pre> <p>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.</p> <pre><code>1279141923.jpg, john (owner name) 1279141925.jpg, john 1279141927.jpg, john 1279141929.jpg, mike 1279141933.jpg, john </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload