Genesis 37:36
34 Then Jacob tore his clothes, put on sackcloth, and mourned for his son many days. 35 All his sons and daughters stood by him to console him, but he refused to be consoled. “No,” he said, “I will go to the grave mourning my son.” So Joseph’s father wept for him. 36 Now in Egypt the Midianites sold Joseph to Potiphar, one of Pharaoh’s officials, the captain of the guard.
Genesis 39:1
1 Now Joseph had been brought down to Egypt. An Egyptian named Potiphar, an official of Pharaoh and the captain of the guard, purchased him from the Ishmaelites who had brought him there. 2 The Lord was with Joseph. He was successful and lived in the household of his Egyptian master. 3 His master observed that the Lord was with him and that the Lord made everything he was doing successful.
Notes and References
"... In J the Ishmaelites bring Joseph to Egypt and sell him to Potiphar; in E it is the Midianites. (They are also referred to as Medanites below. Note that the births of both Midian and Medan come from E, Genesis 25:2, 4) The Redactor of J and E combined these by making it appear that the Midianites sell him to the Ishmaelites, who then sell him in Egypt. But this still leaves a contradiction, because verse 36 (E) still says that the Midianites (or Medanites) sell him to Potiphar, but 39:1 (J) says that “Potiphar ... bought him from the hand of the Ishmaelites who had brought him down there” ..."
Friedman, Richard Elliott The Bible with Sources Revealed: A New View Into the Five Books of Moses (p. 94) Harper San Francisco, 2005