SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    query conditions workings

    HI,

    I think the answer may be yes but I need to be sure...

    If I query my table, and I have a WHERE and 2 AND clauses; do they each reduce the data set that the next clause has to deal with such that the query becomes leaner as it is processed or; do they all get applied at the same time, at the end of the query?

    say I query this

    Code MySQL:
    select 
      country
    , state
    , town
    from addresses as AD
    left outer join 
    possible_countries as PC
    on PC.country = AD.country
    and PC.state = AD.state
    where AD.country = 'France'
    AND AD.state = 'Quebec'
    and '[mathematical calc here]'

    Will the WHERE & 1st AND reduce the data that the 2nd AND must manipulate?

    bazz

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i expect all the WHERE conditions on the AD table are processed together, during retrieval of rows from the AD table

    whatever rows pass those filters are then matched to PC rows

    you can see the sequence of operations by doing an EXPLAIN

    p.s. does france actually have a quebec province?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Rudy, I'll do an explain to try to understand.

    Quote Originally Posted by r937 View Post
    p.s. does france actually have a quebec province?

    lol, no. That was just example data.

    bazz


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
  •