There is a definite connection between the notes of the melody and the notes of the chord.
This is a big subject and musicians love to break the rules, so this explanation will be short and imperfect—but should give you the basic idea.
You can think about it as “which chords fit this melody?” or “what melody would go with these chords?”: a song can be written either way round!
- For the first question, see the article “Learn To Harmonize By Ear” which explains how you put chords to a melody.
If you’re interested in playing by ear or e.g. improvising on saxophone, you’re probably more interested in the second question.
Both the melody and the chords will generally draw their notes from the song’s key, i.e. its scale. It’s generally “safe” to play any notes from that scale in the melody, but the notes which sound best will be the ones from the chord currently being played.
A simple way to put this into practice would be playing the chord’s notes, for example playing an arpeggio or broken chord. However, to keep things interesting you will probably want to branch out from just these notes. You might choose to introduce notes in between those (but still from the scale), or add grace notes (or “blue notes”) which sax players would often do by bending the pitch down a bit to add expression.