1 Samuel 30:6-25 (NASB):
Moreover David was greatly distressed because the people spoke of stoning him, for all the people were embittered, each one because of his sons and his daughters. But David strengthened himself in the Lord his God.
Then David said to Abiathar the priest, the son of Ahimelech, “Please bring me the ephod.” So Abiathar brought the ephod to David. David inquired of the Lord, saying, “Shall I pursue this band? Shall I overtake them?” And He said to him, “Pursue, for you will surely overtake them,and you will surely rescue all.” So David went, he and the six hundred men who were with him, and came to the brook Besor, where those left behind remained. But David pursued, he and four hundred men, for two hundred who were too exhausted to cross the brook Besor remained behind.
Now they found an Egyptian in the field and brought him to David, and gave him bread and he ate, and they provided him water to drink. They gave him a piece of fig cake and two clusters of raisins, and he ate; then his spirit revived. For he had not eaten bread or drunk water for three days and three nights. David said to him, “To whom do you belong? And where are you from?” And he said, “I am a young man of Egypt, a servant of an Amalekite; and my master left me behind when I fell sick three days ago. We made a raid on the Negev of the Cherethites, and on that which belongs to Judah, and on the Negev of Caleb, and we burned Ziklag with fire.” Then David said to him, “Will you bring me down to this band?” And he said, “Swear to me by God that you will not kill me or deliver me into the hands of my master, and I will bring you down to this band.”
When he had brought him down, behold, they were spread over all the land, eating and drinking and dancing because of all the great spoil that they had taken from the land of the Philistines and from the land of Judah. David slaughtered them from the twilight until the evening of the next day; and not a man of them escaped, except four hundred young men who rode on camels and fled. So David recovered all that the Amalekites had taken, and rescued his two wives. But nothing of theirs was missing, whether small or great, sons or daughters, spoil or anything that they had taken for themselves; David brought it all back.So David had captured all the sheep and the cattle which the people drove ahead of the other livestock, and they said, “This is David’s spoil.”
When David came to the two hundred men who were too exhausted to follow David, who had also been left at the brook Besor, and they went out to meet David and to meet the people who were with him, then David approached the people and greeted them. Then all the wicked and worthless men among those who went with David said, “Because they did not go with us, we will not give them any of the spoil that we have recovered, except to every man his wife and his children, that they may lead them away and depart.” Then David said, “You must not do so, my brothers, with what the Lord has given us, who has kept us and delivered into our hand the band that came against us. And who will listen to you in this matter? For as his share is who goes down to the battle, so shall his share be who stays by the baggage; they shall share alike.” So it has been from that day forward, that he made it a statute and an ordinance for Israel to this day.