You will often come across myth discussed alongside any of the Greek tragedies you study. This is simply because the Greeks tended to refer to myths for the source of plots for their plays, rather than to invent plots of their own or to dramatize real-life events (in fact, Phrynichus' play, The Sack of Miletus, got him a fine of 1000 drachmas for doing exactly that).
This is, perhaps, where the inevitability so often associated with Greek Tragedy stems from: many or most of the Athenian audience who first watched these plays at the City Dionysia and other dramatic festivals would be familiar with the story of Oedipus - and know what to expect as soon as they heard his name.
The story that they would have known is the same as that of Sophocles’ play. What is compelling, however, is the way Sophocles chooses to dramatize it – the precise way he packages the well-known story into a play. The story of Oedipus itself is by no means Sophocles’ invention, but he reorganizes the way the information is given so as to provide maximum tension.
The story of the myth is as follows – in chronological order:
The King of Thebes was Laius, a descendant of Cadmus, and an oracle predicted, before the birth of his son, that this son would one day be his father’s murderer. When born, Laius (and, in some versions of the myth, Jocasta, Oedipus’ mother and Laius’ wife) gives the child to a herdsman and orders him to take him out beyond the city and kill him. Out of pity for the child, the herdsman gave the baby to another herdsman, tying his feet together and wounding them (in some versions, Laius pierces Oedipus’ feet and exposes him to die, where the herdsman finds him by chance). This herdsman took the baby to Polybus, King of Corinth, who adopted him as his own son.
Oedipus, now fully grown, is told that he is not the son of Polybus, and seeks help from an oracle, who tells him he is destined to kill his father and sleep with his mother. Oedipus – presumably still thinking that Polybus is his father – flees from Corinth to Thebes in an attempt to escape the fate the oracle has predicted for him. As he is travelling, he gets involved in a dispute at a crossroads with a man in a chariot (Laius, his birth father) – and kills him.
As he approaches Thebes, Oedipus is approached by the Sphinx, who proposes her famous riddle: ‘What walks on four feet in the morning, two in the afternoon, and three at night?’ – the answer is man, who crawls, walks upright, and in his age, walks with a stick. The Sphinx, who has been plaguing Thebes, is defeated – Oedipus has solved the riddle that no Athenian could solve. In gratitude, the Thebans appoint Oedipus the king of Thebes (in Laius’ place) and reward him with the dead king’s wife, Jocasta, his birth mother. Oedipus and Jocasta have four children: two daughters (Electra and Ismene) and two sons (Polyneices and Eteocles).
At this point, Sophocles' play begins. Years later, a plague strikes Thebes, and Oedipus as King promises to end it. He sends Creon, Jocasta’s brother, to the Delphic Oracle to seek guidance and is told that the murderer of Laius must be found and either killed or exiled (depending, again, on which version you read). As he begins to search for the killer, he encounters (or sends for) Tiresias, who tells him that he is the killer of Laius and warns him that he will only be seeking out himself. Oedipus ignores this advice.
A messenger arrives from Corinth giving Oedipus the news that Polybus is dead, and it seems the oracle’s prophecy for Oedipus has failed to come true. The herdsman who delivered him to Corinth then appears and informs Oedipus that he is an adopted baby. Jocasta, hearing this, realizes what has happened and kills herself. Oedipus seeks out the herdsman initially ordered to murder him as a baby, and learns that the infant raised by Polybus and Merope (his wife) was in fact the son of Laius and Jocasta. He finally realizes that, at the crossroads, he killed his father, and is married to his own mother. Notably in Sophocles' play, the Corinthian Messenger is also the first herdsman: a small, but concise tweak.
Oedipus finds Jocasta dead, and blinds himself. He then (in Sophocles) leaves the city, and with his daughter Antigone as his guide, wanders blindly through the country, dying finally at Colonos. Some versions of the story have Oedipus commit suicide in Thebes, rather than leave or be exiled.