I remember having read a short story in which the main character, thanks to a series of happenings also involving time travel, grew up, changed sex, made sex with himself and had a son... who of course was himself. The story ended with the main character saying something like "I know where I come from: but what about you?" As you may guess, I don't have enough data to search for the title, so I am asking knowledgeable people :-)
I'm pretty sure this is Robert Heinlein's All You Zombies.
And the quote is; "I know where I came from—but where did all you zombies come from?"
I also think this question is a duplicate but I couldn't find the original on this site.
This would be All You Zombies, a short story by Robert A. Heinlein:
"'—All You Zombies—'" chronicles a young man (later revealed to be intersex) taken back in time and tricked into impregnating his younger, female self (before he underwent a sex change); he thus turns out to be the offspring of that union, with the paradoxical result that he is his own mother and father. As the story unfolds, all the major characters are revealed to be the same person, at different stages of her/his life.
There's a movie based on that: Predestination
Plot summary from Wikipedia:
A person goes back in time in order to catch an infamous terrorist known as the "Fizzle Bomber"—the agent stops the bomb, but is severely injured. The Fizzle Bomber escapes and the agent travels into the future, to 1992, using a coordinate transformer field kit—a time machine disguised as a violin case—with the help of an unknown person. The agent awakens to find that he has undergone cosmetic surgery to save his life.
It is revealed that the agent works for a mysterious organization, known as the Temporal Bureau, that sends so-called "temporal agents" through time to prevent major crimes, and the Fizzle Bomber is the only criminal to elude them thus far. In March 1975, the Fizzle Bomber kills 11,000 people in New York City.
Once the agent is healed, he is ordered to embark on a final mission before he is decommissioned. The agent uses his coordinate transformer field kit to travel back to the 1970s to work as a bartender in New York City. A male customer, whose "Unmarried Mother" pen name is used for writing magazine confessional testimonials, enters the bar to drink alcohol.
Cajoled by the bartender, the Unmarried Mother proceeds to tell a story that he considers remarkable: He was born in 1945 and placed in an orphanage, as he was abandoned. Identified as a female, he is raised as "Jane." As a young woman, Jane later tries to join the Space Corps and excels in the recruitment tests; but, Jane is disqualified when Space Corps doctors discover something about her physiology.
After being expelled from Space Corps, Jane attends night classes in Cleveland, US, where she meets and falls pregnant to an older man who eventually disappears. After finding out that she is pregnant to the older man, Jane brings the pregnancy to full term and, during the delivery of her child, the doctors discover the condition that led to her expulsion: Jane was born intersex, with both female and male reproductive organs, allowing Jane to give birth to a baby with her female reproductive organs. However, her baby is kidnapped by an unknown man while still in hospital. At the advice of her physician, Jane then undergoes further procedures to remove her female sexual organs—irreparable after birth complications—thereby becoming a man named John.
Unmarried Mother concludes the story, and the bartender suddenly reveals that he knows the identity of the older male who left Jane, and offers John the chance to kill him. They both travel back in time to Cleveland and the bartender gives John a gun to enact the killing. However, John instead meets Jane, his younger female self, while the bartender/temporal agent uses his time machine to travel into the future—in his final opportunity to catch the Fizzle Bomber. However, the agent is knocked out by the bomber.
The bartender is later shown to be the kidnapper of Jane's baby, before he meets back up with John, who has had sex with his earlier self, Jane, by this time. The bartender convinces John to abandon Jane and start working as a Temporal Agent at the Temporal Bureau.
Having completed his final mission, the bartender is instructed to choose his time and place of retirement—upon his arrival at that location, his field kit will be automatically decommissioned. He chooses to retire in a New York City apartment, around the time of the Fizzle Bomber's March 1975 bombing, after receiving an envelope from his supervisor, Robertson. Upon his arrival, the field kit displays an error message after it is decommissioned; however, the retired agent does not report the error and opens the envelope which contains an instruction related to the March 1975 bombing.
The agent eventually discovers that the Fizzle Bomber is an older version of himself. After arguing with his older self, he kills him with a handgun in a laundromat. A flashback scene then reveals that the agent is in fact Jane/John—completely changed after the reconstructive surgery at the beginning of the film—and finishes with John seated in the New York City apartment that he had requested for retirement.