MySQL Combine SELECT results in rows -


Assume that I have 2 similar tables like this:

  table1 table2 + -------- + ------ + + -------- + ------ + | Fruit | Year | | Fruit | Year | + -------- + ------ + + -------- + ------ + | Apple 2015 | | Apple 2014 | | Banana | | 2014 | | Apple 2013 | | Banana | | 2013 | | Banana | | 2011 | + -------- + ------ + + -------- + ------ +  

I would like to have each table Get last year for fruit in:

  + -------- + --------- + ------- - + | Fruit | T1.last | T2.last | + -------- + --------- + --------- + | Apple 2015 | 2014 | | Banana | | 2014 | 2011 | + -------- + --------- + --------- +  

For a table with this one simple It is possible to select the statement:

  SELECT fruits, Max (year) Table 1 from the final result by group: + -------- + ------ + | Fruit | Last | + -------- + ------ + | Apple 2015 | | Banana | | 2014 | + -------- + ------ +  

I do not know how to add the last year for each fruit from the second table, the form of an adjacent line In.

simply join two tables.

  SELECT Fruit, Max (T.Uure) AS`T1 Enst ', Max (T.Year) AS T2 T2 Usage (Fert) Group to Food as Table 1 to T1 Join Tables 2 Demo: 


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -