Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to join three degrees in mySQL
  2. SELECT posts.id, posts.text, users.id, users.name, comments.text AS commentText, commenters.id, commenters.name
  3. FROM posts
  4.     JOIN users
  5.         ON posts.userId = users.id
  6.     LEFT JOIN comments
  7.         ON posts.id = comments.postId
  8.             LEFT JOIN users AS commenters
  9.                 ON comments.userId = users.id
  10.         WHERE posts.id = @postId
  11.        
  12. SELECT posts.id, posts.text, users.id, users.name, comments.text AS commentText, commenters.id, commenters.name
  13. FROM posts
  14.     JOIN users
  15.         ON posts.userId = users.id
  16.     LEFT JOIN comments
  17.         ON posts.id = comments.postId
  18.             LEFT JOIN users AS commenters
  19.                 ON comments.userId = commenters.id