SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: does the order in where clauses matter?

  1. #1
    SitePoint Addict thoresson's Avatar
    Join Date
    Dec 2002
    Location
    Gothenburg, Sweden
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    does the order in where clauses matter?

    I just realized that the order in where clauses matters. Or at least seems to. These two sql statements does not retrieve the same result:

    PHP Code:
    SELECT count(*) AS new FROM commentsuser2albumalbum WHERE album.user_id '2' AND comments.album_id album.album_id AND comments.comment_date '2004-11-28 12:06:06' AND user2album.user_id '1' 
    PHP Code:
    SELECT count(*) AS new FROM commentsuser2albumalbum WHERE album.user_id '1' AND comments.album_id album.album_id AND user2album.user_id '2' AND comments.comment_date '2004-11-28 12:06:06' 
    Why?
    //Anders

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,457
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    they produce different results because they are different queries

    query 1: album.user_id = '2' and user2album.user_id = '1'
    query 2: album.user_id = '1' and user2album.user_id = '2'

    different queries, different data, different results
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict thoresson's Avatar
    Join Date
    Dec 2002
    Location
    Gothenburg, Sweden
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Sometimes one doesn't see the most obvious. Thanks.
    //Anders

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
  •