Proverbs 1:10 My son, if sinners entice thee, consent thou not. 11 If they say, Come with us, let us lay wait for blood, let us lurk privily for the innocent without cause: 12 Let us swallow them up alive as the grave; and whole, as those that go down into the pit, 15 My son, walk not thou in the way with them; refrain thy foot from their path.
This is what Joab had failed to do on more than one occasion, as David ordered him to do that which he knew was an act of wrongdoing. For example, when David told him to put Uriah in the forefront of the battle, and retire from him, so that he be slain, Joab obeyed, for his allegiance was given to the king, and for this reason he worshiped David rather than God.
2nd Samuel 11: 14 And it came to pass in the morning, that David wrote a letter to Joab, and sent it by the hand of Uriah. 15 And he wrote in the letter, saying, Set Uriah in the forefront of the hottest battle, and retire ye from him, that he may be smitten, and die. 16 And it came to pass, when Joab observed the city, that he assigned Uriah unto a place where he knew that valiant men were. 17 And the men of the city went out, and fought with Joab: and there fell some of the people of the servants of David; and Uriah the Hittite died also.
Again, when David commanded him to number the people, he remonstrated, yet, even though it went against his grain, and his conscience bothered him, he went along with it, for David meant more to him than God, and as a result, Joab would ultimately be worshiping a mortal man instead of God in heaven as he obeys David in numbering the people.
1st Chronicles 21:3 And Joab answered, The Lord make his people a hundred times so many more as they be: but, my lord the king, are they not all my lord's servants? why then doth my lord require this thing? why will he be a cause of trespass to Israel?
May The Lord add His blessing to the study of His word. God bless!