9/26/2014 - 2:13 PM

Simple Inner Join

Simple Inner Join

/*Simple Inner Join action.  Joins all rows on both tables as long as there is a match between coluns in both tables. 
  These are two separate join actions. 
	Joining the tables grade_levels (gl) and consumer_series (cs) on commonanlity 'consumer_series_id'. 
	Joining tables models(m) and grade_levels(gl) on commonality 'grade_level_id'.
  This part expresses the commonality : on <<aliasTableName1>>.<<commonValue>> = <<aliasTableName2>>.<<commonValue>>

distinct gl.grade_level_id, grade_level_name
consumer_series cs 

join grade_levels gl 
  on cs.consumer_series_id = gl.consumer_series_id 

join models m
  on m.grade_level_id = gl.grade_level_id
  cs.display_name = 'tundra'
  and m.model_year = cs.current_model_year
  and m.active_flag = 1
  and m.nonconsumer_flag = 0