FROM clause - easy syntax question

  • Hello,

    I have an syntax (possibly considered n00b) question. What does this syntax mean:

    Create Table #tmpDates(xDate datetime)

    Select foo.Facility, #tmpDates.xDate

    from (fooTable foo      

     inner join barTable bar on foo.id = bar.ForeignKey), #tmpDates      

    WHERE foo.Date <= @EndDate ....

    Specifically: the parenthesis around the the from table and the join and then the comma before the temp table. I have never seen this syntax - where the from clause is in parenthesis and then another table afterwards. I've looked in BOL but can't seem to locate what exactly is going on. Does the comma mean that you want to select from both tables (kinda like the keyword UNION?)

    Thanks,

    Nate

  • comma means a join between result of

     (fooTable foo      

     inner join barTable bar on foo.id = bar.ForeignKey)

    and #tmpDates


    Kindest Regards,

    Vasc

  • Thanks for the ultra fast reply Vasc.

    After pondering on this enlightenment...

    For clarification: Is it considered to be an outer, inner or some other type join? How does it know what to join on? Can it just join in some default order?

    Or is it a Cartesian (Cross) join?

    I know it's probably obvious to many, but it's not clicking with me for some reason.

    Thanks,

    Nate

  • from (fooTable foo

    inner join barTable bar on foo.id = bar.ForeignKey) is an inner join

    ..., #tmpDates >> is a cross join

    but if you then add a where condition where #tmpDates = SomeOtherCol, it becomes an inner join again.

  • Cool. Thanks. You guys are awesome.

    Nate

  • HTH.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply