Note that there are some explanatory texts on larger screens.

plurals
  1. POTough mySQL select query
    primarykey
    data
    text
    <p>I'm stuck with a weird situation. It goes like this:</p> <p>I have 2 tables. One is called users, which has all my user/password details, then I have another table called userFiles, which has a user ID and a fileID for a file which he has rights to.</p> <p>Now, note that 1 account can have rights to multiple files, and multiple accounts can have rights to 1 file.</p> <p>So basically, the first table has, say:</p> <ol> <li>ID: 1, name: bob, password: helloWorld</li> <li>ID: 2, name: phil, password: what'sUp?</li> </ol> <p>and in table 2, say:</p> <ol> <li>uID: 1, fID: 67</li> <li>uID: 1, fID: 68</li> <li>uID: 1, fID: 36</li> <li>uID: 2, fID: 67</li> <li>uID: 2, fID: 68</li> <li>uID: 2, fID: 102</li> </ol> <p>Now, here's what I want to do:</p> <p>I want to SELECT All the users! (in this case both!), also, I want to JOIN the other table, but I only wanna join the row where I specify a particular fID!</p> <p>For example, I wanna query for users and user right with fID 67</p> <p>I wanna get this:</p> <ol> <li>ID: 1, name: bob, password: helloWorld, uID: 1, fID: 67</li> <li>ID: 2, name: phil, password: what'sUp?, uID: 2, fID: 67</li> </ol> <p>and, for fID 102 (even if it gives a value other than NULL, that i can use in my PHP code, it's fine)</p> <ol> <li>ID: 1, name: bob, password: helloWorld, uID: NULL, fID: NULL</li> <li>ID: 2, name: phil, password: what'sUp?, uID: 2, fID: 102</li> </ol> <p>This is the query I've tried using</p> <pre><code>SELECT * FROM users LEFT JOIN userFiles ON users.ID=userFiles.uID WHERE userFiles.fID = 102 </code></pre> <p>However, this query only returns one row, while I wan't both.</p> <p>If you can't gimme a mySQL solution, try and help me out so that I can filter out results, and obtain something like what I want using PHP...</p> <p>Thanks a ton!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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