title: Duplicate rows when attempting a 5 table join
body: <p><strong>Background:</strong> First post so go easy on me! ;-) I'm having some problems with a SQLite join across 5 tables. I'm building a watering system on my Raspberry Pi, using Python, with the following table structure built in SQLite:</p>
  
  <p><strong>deviceTable</strong> - table lists all watering devices</p>
  
  <p><strong>programTable</strong> - table listing all watering programs</p>
  
  <p><strong>zoneTable</strong> - table listing all watering zones </p>
  
  <p><strong>assignProgramTable</strong> - bridging table for assigning many watering program to many zones</p>
  
  <p><strong>assignDeviceTable</strong> - bridging table for assigning many devices to many watering zones.</p>
  
  <p><strong>Problem:</strong> I'm currently using the following query to try and join all of these tables together so that I can begin to control my Raspberry Pi with a multi-threaded Python script... I originally had this working as a nested SQL script (working dynamically in my Python script), but it got a little complex when trying to run multiple thread within a database results. Essentially I plan to take a number of key values from the SQL query and </p>
  
  <p>There appears to be multiple rows  being returned when there should only be one for each entry.. any idea of the best way to handle this? I've found a number of answers suggesting to use the DISTINCT option (which didn't work), although am I going about this the best way possible?</p>
  
  <pre><code>SELECT * 
  FROM deviceTable AS d, programTable AS p 
  JOIN assignDeviceTable AS ad ON d.deviceID = ad.deviceID 
  JOIN zoneTable AS z ON z.zoneID = a.zoneID 
  JOIN assignProgramTable AS a ON p.programID = a.programID 
  where p.programStatus = "1"
  </code></pre>
  
  <p>Following LS_dev's advice, I've updated the query to the following: </p>
  
  <pre><code>SELECT * 
  FROM deviceTable AS d, programTable AS p, assignDeviceTable AS ad, zoneTable AS z, assignProgramTable AS ap 
  JOIN deviceTable ON d.deviceID = ad.deviceID
  JOIN assignDeviceTable ON ad.zoneID = z.zoneID 
  JOIN zoneTable ON z.zoneID = ap.zoneID 
  JOIN assignProgramTable ON ap.programID = p.programID  
  where p.programStatus = "1"
  </code></pre>
  
  <p>Unfortunately this resulted in even more rows being duplicated... still stuck! </p>