SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    USA
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question on 2 mySQL querys..

    These 2 sql querys accomplish the same thing, which is better? Why?

    SELECT a.title, a.body, u.username, u.email, u.profile FROM article a, author u WHERE a.authorid = u.authorid AND a.articleid = 5 AND a.status = 1

    SELECT a.title, a.body, u.username, u.email, u.profile FROM article a LEFT JOIN author u ON (a.authorid = u.authorid) WHERE a.articleid = 5 AND a.status = 1

  2. #2
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Both do virtually the same thing (in this case, as in most cases, they'll get you the same records). The one using LEFT JOIN is conformant to the ANSI 92 standard, and is therefore "better" in that sense. As far as efficiency goes, I'd be surprised to see much of a difference between the two.

    Short answer - use either. I'd choose the LEFT JOIN one purely because it's written to ANSI standard and slightly easier to read, but both are very common and neither is "bad".

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    USA
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, I think I will use LEFT JOIN.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •