title: How to handle many-to-many relationships in a single sql query?
body: <p>I've been running SQL calls all morning, without any luck on getting the correct kind of data that I want to return.  I did a few searches and found some information on Joining 2 tables, but nothing that pulls from a table, that pulls from a table.  This can sound confusing by wording so I crafted a diagram of the sort of information I'm looking to get.  </p>
  
  <p><img src="https://i.stack.imgur.com/uqZ1n.png" alt="enter image description here"></p>
  
  <p>I have tried things like, </p>
  
  <pre><code>select * from Users 
  left join UserLibs on UserLibs.userId = Users.UserId
  WHERE Users.username='testname'
  </code></pre>
  
  <p>That however doesn't give me the library name.  </p>
  
  <p>So then I tired to join the column with another table and column. </p>
  
  <pre><code>select * from users
  left join UserLibs on userLibs.userId = Users.UserId AND left join Libraries on  UserLibs.libraryId = Libraries.libraryName
  where Users.username='test';
  </code></pre>
  
  <p>Which also didn't produce results, just errors.  Any help with this would be awesome.  </p>
  
  <h2>UPDATE</h2>
  
  <p>I just wanted to add my final solution that worked for my situation.  </p>
  
  <pre><code>SELECT Users.userId, Users.username, Users.editLibraries, Users.editAnnouncements, Users.editServices, 
     Users.editNormalHours, Users.editSpecialHours, Users.editUsers, Users.editSemesters, 
     Libraries.libraryName, LibraryDepartment.departmentName
      FROM Users
      LEFT JOIN UserLibs on Users.userId = UserLibs.userId
      LEFT JOIN Libraries on UserLibs.libraryId = Libraries.id
      LEFT JOIN UserDepts on Users.userId = UserDepts.userId
      LEFT JOIN LibraryDepartment on UserDepts.departmentId = LibraryDepartment.ldId
      WHERE Users.username='testname';
  </code></pre>