SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27
  1. #26
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man, I am a shame that I couldn't understand the first tiem it is clear Now I will make an extra effort to avoid you coming to simple language. I understood it I just need to add the other condition to the JOIN.
    WHERE category_id = ".$idc."
    As you were going to the steps in the last post, I wonder why not AND instead of WHERE in the INNER JOIN after ON. It seems that the language has change.

    FROM products INNER JOIN categories
    ON categories.id = products.category_id
    WHERE category_id = ".$idc."
    Why not

    FROM products INNER JOIN categories
    ON categories.id = products.category_id
    AND category_id = ".$idc."
    it just a question Mr.

    From what I understand AND means that both of the conditions need to be true categories.id = products.category_id AND category_id = ".$idc.".

    Now I can see you have put WHERE what's is the underline of changing?

    The only thing I can figure out is using where to make the sentence Longer in case there is more condition and use AND after where or even have other possibilities and other options to a different query.

  2. #27
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,269
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    you ask a very good question

    yes, in the INNER JOIN query, the category_id = ".$idc." condition can be either in the ON clause or the WHERE clause -- they will produce the same results *

    however, i prefer to put it into the WHERE clause because when you think about it, it doesn't really define a join condition, but rather a filter condition

    * except that it makes a very big difference where such a condition is located if it's an OUTER JOIN

    i hope that as you gain more experience with different types of joins, these questions will become easier

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


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
  •