Note that there are some explanatory texts on larger screens.

plurals
  1. PO>, <, <>, = Operators for Inner Join Conditions
    primarykey
    data
    text
    <p>My boss threw this code my way and I am having a hard time understanding how the inner join's last ON statement works. I don't think he understands it completely either (but it gets the job done). Really just interested in learning more about how SQL works. Thank you so much!</p> <p>Here is the On Statement</p> <pre><code>and (A.Submitted_Date &gt; X.Submitted_Date))) </code></pre> <p>And here is the query</p> <pre><code> SELECT AA.ID, AA.Submitted_Date as Date_Status FROM Report as AA where AA.Submitted_Date in --START ( SELECT X.Submitted_Date FROM Report as A inner join --Start Find All Dates Submitted ( SELECT [ID],[Submitted_Date] FROM Report where not(Submitted_Date is null and Cleared_Date is null) group by ID, Submitted_Date) as X --End Find all Dates Submittd --below is the conditions of the join ON A.ID = X.ID and A.ID= AA.ID --THIS IS THE CONDITION I AM CONFUSED ABOUT!!!! and (A.Submitted_Date &gt; X.Submitted_Date))) group by X.Submitted_Date) and not AA.Submitted_Date is null group by AA.ID, AA.Submitted_Date </code></pre> <p>Here is a Sample of Dates From Table A</p> <pre><code>2012-11-27 00:00:00.000 2012-11-27 00:00:00.000 2012-11-27 00:00:00.000 2012-12-10 00:00:00.000 2012-11-27 00:00:00.000 2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-12 00:00:00.000 </code></pre> <p>Here is a Sample of Dates from Table X</p> <pre><code>2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-10 00:00:00.000 2012-12-12 00:00:00.000 </code></pre> <p>Here is the Result before The Last Condition</p> <pre><code>2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-10 00:00:00.000 2012-12-12 00:00:00.000 </code></pre> <p>Here is the result with A.Sub > X.Sub</p> <pre><code>2012-11-27 00:00:00.000 2012-11-29 00:00:00.000 2012-12-05 00:00:00.000 2012-12-10 00:00:00.000 </code></pre> <p>I am confused on why those dates show up. What is being compared between A and X? Won't the values in A be the same as X always, therefore resulting in no final data? Thank you for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload