שְׁלשָׁה סְפָרִים כָּתַב: מִשְׁלֵי, וְקֹהֶלֶת, שִׁיר הַשִּׁירִים. אֵי זֶה מֵהֶן כָּתַב תְּחִלָּה, רַבִּי חִיָּא רַבָּה וְרַבִּי יוֹנָתָן, רַבִּי חִיָּא רַבָּה אָמַר מִשְׁלֵי כָּתַב תְּחִלָּה, וְאַחַר כָּךְ שִׁיר הַשִּׁירִים, וְאַחַר כָּךְ קֹהֶלֶת, וּמַיְתֵי לָהּ מֵהַאי קְרָא (מלכים א ה, יב): וַיְדַבֵּר שְׁלשֶׁת אֲלָפִים מָשָׁל, מָשָׁל זֶה סֵפֶר מִשְׁלֵי, וַיְהִי שִׁירוֹ חֲמִשָּׁה וָאָלֶף, זֶה שִׁיר הַשִּׁירִים, וְקֹהֶלֶת בַּסּוֹף אָמַר. מַתְנְיָיתָא דְרַבִּי חִיָּא רַבָּה פְּלִיגָא עַל הָדֵין שְׁמַעְתָּא, מַתְנִיתָּא אָמְרָה שְׁלָשְׁתָּן כָּתַב כְּאַחַת, וּשְׁמַעְתָּא אָמְרָהּ כָּל חַד וְחַד בִּפְנֵי עַצְמוֹ. תָּנֵי רַבִּי חִיָּא רַבָּה רַק לְעֵת זִקְנַת שְׁלֹמֹה שָׁרְתָה עָלָיו רוּחַ הַקֹּדֶשׁ וְאָמַר שְׁלשָׁה סְפָרִים: מִשְׁלֵי, וְקֹהֶלֶת, וְשִׁיר הַשִּׁירִים. רַבִּי יוֹנָתָן אָמַר שִׁיר הַשִּׁירִים כָּתַב תְּחִלָּה, וְאַחַר כָּךְ מִשְׁלֵי, וְאַחַר כָּךְ קֹהֶלֶת, וּמַיְתֵי לָהּ רַבִּי יוֹנָתָן מִדֶּרֶךְ אֶרֶץ, כְּשֶׁאָדָם נַעַר אוֹמֵר דִּבְרֵי זֶמֶר, הִגְדִיל אוֹמֵר דִּבְרֵי מְשָׁלוֹת, הִזְקִין אוֹמֵר דִּבְרֵי הֲבָלִים. רַבִּי יַנַּאי חָמוּי דְּרַבִּי אַמֵּי אָמַר הַכֹּל מוֹדִים שֶׁקֹּהֶלֶת בַּסּוֹף אֲמָרָהּ.
[King Solomon] wrote three books: Proverbs, Ecclesiastes, and Song of Songs. Which one did he write first? Rabbi Hiyya, Rabbah, and Rabbi Yochanan said Proverbs was written first, then Song of Songs, then Ecclesiastes, and based it on this source: (I Kings 5:12) "He composed three thousand proverbs," 'proverbs' is the book of Proverbs. "And his songs numbered one thousand and five," this is Song of Songs, and Ecclesiastes he wrote last ...
A text teaches that he wrote the three at the same time ...
Rabbi Hiyya and Rabbah taught that Solomon only had the holy spirit upon him during old age and wrote the three books: Proverbs, Ecclesiastes, and Song of Songs.
Rabbi Yochanan said Song of Songs was written first, then Proverbs, then Ecclesiastes. And what is the basis for Rabbi Yochanan? From the way of the world - when a person is young he offers words of song, when he ages he offers proverbs, when he gets old he offers cynicism. Rabbi Yannai said in the name of Rabbi Ami: "All agree that Ecclesiastes was written last."