1 Chronicles 18–20 record David's wars with immediate neighbors of Israel. The chapters are organized chiastically:
A. War with Philistia and Moab, 18:1
B. War with Ammon, Aram, and Edom, 18:2-13
C. David reigns with justice and righteousness, 18:14-17
B'. War with Ammon and Aram, 19:1-20:3
A'. War with Philistia, 20:4-8
There are good reasons to conclude that B and B' describe the same war. Both involve both Aram and Ammon; in both, David captures 7000 charioteers (18:4; 19:18); the number of infantry is somewhat confusing, but the 20,000 + 22,000 of 18:4–5 is roughly equal to the 40,000 of 19:18. William Johnstone (1 &2 Chronicles) points out that it would have been impossible for Hadadezer to mount a second campaign after a defeat as devastating as that described in 18:3-4. Putting the two accounts together clarifies some details. David defeats Hadadezer when he goes to establish his hand at the Euphrates (18:3), and 19:16–19 explains what Hadadezer was doing there: He was organizing an alliance to fight David.
19:1-20:3, then, describes in more detail the circumstances that led to the Ammonite war, and Joab's and David's conduct of that war. That longer account is also arranged chiastically:
A. Beginning of War with Ammon, 19:1–5
B. Ammon allies with Aram, 19:6–9
C. First war with Aram: Joab wins, 19:10–15
C'. Second war with Aram: David wins, 19:16–18
B'. Aram makes peace with David, 19:19
A'. Joab takes Rabbah of Ammon, 20:1–3
Though the frame concerns the cause (Hanun's insult of David's messengers) and conclusion (David wears the Ammonite crown) of the Ammonite war, the center is concerned with Ammon's alliance with Aram. The Arameans provide the overwhelming chariot force (32,000, 19:7; think tanks), and they are the ones who regroup to fight again (19:16). Joab's and David's battles both focus on fighting Arameans (19:14, 18).
The war with Aram is cosmic, holy war. “Hadadezer” contains the divine name “Hadad,” the proper name of the god often known as Baal (a title, “Master”); his name means “Hadad helps.” But Hadad doesn't, Hadadezer's soldier's aren't much help to Ammon (18:5; 19:19).
David defeats Ammon by first defeating Aram. Defeated twice, Aram breaks their alliance with Ammon and seeks a covenant of peace with David. It's a divide and conquer strategy: Once he has made peace with Aram, Ammon can no longer resist.