What is the difference between Shrimad Bhagavatam and Bhagavad Gita?
Srimad Bhagavatam or the Bhagavat Puran, is the 5th major purana amongst 18 different puranas. It contains 12 different parts (skandhas) and around 18,000 verses. Similar to the other Puranas, the Srimad Bhagavatham is written by Sage Vyasa. Sage Shuka, who was Vyasa's son, recited the Bhagavatam to King Parikshit who was cursed to die in 7 days, by Sage Shrungi.
Bhagavad Gita is a part of the Bhisma Parva (the 6th part) of the Mahabharata. The Gita consists of 18 smaller chapters and is around 700 verses. It was also written by Sage Vyasa (who composed the entire Mahabharata). The Gita was recited by Lord Krishna to Arjuna on the battlefield.
In the Bhagavad Gita, we come to know about Krishna as a diplomat, who imparts his knowledge to Arjuna. In the Bhagavatam (the 10th skandha), we get to know about Krishna as a youthful boy who likes to play games with the gopis. The famous ras leela of Krishna is described in the 10th skandha.
Which is first written? And when and why the later one is written if both are same?
Bhagavad Gita was written prior to Srimad Bhagavatam. Infact, the very first skandha of Srimad Bhagavatam starts of with Sage Narada debating with Sage Vyasa about the Mahabharata
'Oh greatly fortunate son of Parâs'ara, is it so that you find the satisfaction of your soul by identifying yourself with your body and mind? (3) You have done your full enquiries and being well versed, you have prepared the great and wonderful Mahâbhârata to which you have added your extensive explanations. (4) Despite your investigations and the knowledge you acquired about the Absolute and Eternal, you, dear master, lament not having done enough for the purpose of the soul.'
In the next few verses, we can get to know that Sage Narada clearly mentions that Sage Vyasa has written about the 4 virtues in Mahabharata, but has not written anything about the Lord Krishna himself. This sets the stage for Bhagavatam.
(The Srimad Bhagavatam Mahatmyam contains a verse, "ekaa bhagavatam shastram mukti-danena garjati", which translates to roughly, Only the Srimad Bhagavatam loudly declares that reading it would grant you mukti)
Are both of the same author or different books?
Both the books were written by Sage Vyasa. They are completely different books.
Is Bhagavad Gita tells about one avatar and Shrimad Bhagavatam tells about all the Avatars?
The Srimad Bhagavatam tells about all the avatars in the 6th chapter and the 7th chapter of the 2nd skandha.