code_junkie

How to write a SQL statement which gets results via a relationship table? (many to many)

Nov 11th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. SELECT section.*
  2. FROM section
  3. INNER JOIN archive_to_section
  4. ON section.id = archive_to_section.section_id
  5. WHERE archive_to_section.archive_id = $this_archive_id
  6.  
  7. SELECT s.*
  8. FROM section s INNER JOIN archive_to_section ats ON s.id = ats.section_id
  9. WHERE ats.archive_id = 1
  10.  
  11. SELECT s.*
  12. FROM archive_to_section ats
  13. INNER JOIN section s ON s.id=ats.section_id
  14. WHERE ats.archive_id= @archiveID
Add Comment
Please, Sign In to add comment