I've always wondered how come there can be a chord progression with some chord that doesn't belong in the particular scale... Moreover, how can it be possible that this progression is in any key at all (D5 Db5 C5 B5)? Anyway, I just want to learn a lot about the out of scale chords, what happens to the key if I put this outsider chord in the progression, etc.
The chord progressions you want will depend on the sound you're after. You can do quite a lot of creative songwriting without ever straying from the basic "in-key" chords: I-ii-iii-IV-V-vi-[vii], and if the Top 40 charts are any indication, you can make a pantload of money with very "safe" chord progressions. However, if you don't want to be safe, and want to create new sounds, experimentation is encouraged.
Beyond this basic framework, there are some old standbys which work very well in particular places:
Beyond these basic tricks, look at the chords as a movement of voices. Figure out where you want to start and end up, write the notes on a staff (it does help to be able to read music, even for instruments like guitar and bass that rarely use it), then see where each note of that chord can move to transition from one to the other. Most times, your "transition" chord in the middle will only involve one voice moving half a step in either direction, then the chord will resolve as one or both other voices in the triad make a similar move. Don't forget your inversions; if the movements seem too large, you're probably trying to move to the wrong inversion of the chord; drop the top note of one chord by an octave until the movements work better.
EDIT FROM COMMENTS: OK, so you want to know a little more about chords that just don't seem to belong at all. Your specific example is Cmaj7-G7-A7-Fmaj7.
As I stated, try to look at chords as a movement of voices. Let's take these four chords (each one is displayed in a column with the root on the bottom):
B F G E G D E C E B C# A C G A F
First off, you'll notice that these four chords all share a lot of notes in common. The key isn't obvious as there's no obvious tonic triad, but C major is a good guess, although the A7 has a C# which isn't in the key.
Let's rearrange these chords a bit:
G F G F E D E E C B C# C B G A A
All four chords have the same notes, but I've inverted the first and last chords. The Cmaj7 chord is now in its first inversion; the top note, the major 7th, has been dropped into the bass. Now, the movement of each of the four "voices" is reduced; The G moves one whole step down to F, the E moves one whole stepdown to D, the C moves one half step down to B, and the B moves a major third down to G. The second and third chords involve similarly small movements, all a half or whole step up. Then, the move from A7 to Fmaj7 is made easier by writing the Fmaj7 in its "third inversion"; the A, C and E are all dropped into the bass putting the root note on top. Now the only move from A7 to Fmaj7 is for the top "voice" to drop a whole step from G to F.
If we wanted, we could make the progression from first to second even closer:
G G G F E F E E C D C# C B B A A
Now we've put the G7 into its third inversion as well; as a result, when moving from the Cmaj7, every voice moves only a half step, and in addition, the progression moves upward, not downward; if you want the progression to sound happier, you generally want the notes in it to be moving upward.
Let's make some more changes:
G G A A E F G F C D E E B B C# C
Now every chord is in some inverted form; the third chord is in third inversion, and we've shifted the last chord to the second inversion. No voice moves more than one whole step at a time, and except for the last chord, whenever there's a movement, it moves upward. This form also shows one more interesting thing; if you look at the third chord, the A7, you'll notice that in this inversion, you have the tonic, third, fifth and sixth in the key of C major, which is what I'm supposing the overall key of this progression to be. So, the vi7 chord is also the I6 chord, which is part of why it works so well.
B B C# C G G A A E F G F C D E E
Now we start with a definite tonic chord, with the Cmaj7 back in its basic configuration with the C in the bass. G7 and A7 are in their second inversions, and Fmaj7 in its first inversion. This variant of the progression keeps the upward motion, but begins on the tonic instead of ending on the tonic as in the previous variant. Which one's better? Depends on what you want the progression to do.
Try plunking all of these out on a piano and pick out the differences in sound. Also, try other combinations that move the voices in opposing directions, so the chord "opens" or "closes" as it progresses.
As for your question about "resolving", understand that the I chord, the tonic, is the strongest, "most-resolved" chord in any major key. It doesn't get any more fundamental than the tonic, at least to Western ears. The two "second level" chords are the IV and V chords. The IV chord has the root note in it, and the 4 and 6 naturally want to move downwards, "resolving" to the I chord's third and fifth. The V chord is built on the fifth, and has the major seventh which is only a half step from the tonic and so desperately wants to resolve upwards to that root note (which is why the suspended V chord works; it gives you that tonic note), while the 9th, aka the second, can either resolve downwards back to the root, or upwards to the third, either way you end up with a perfect fifth based on the tonic, or with the tonic triad.
Beyond that, most other chords will naturally want to resolve towards one of these three major chords. The ii chord has the 2, 4 and 6, and so can easily resolve to the IV chord (4,6,8). The vi chord (6,8,3) will resolve to the tonic chord, as it has the root and major third, and just needs the sixth to move down. The iii chord (3,5,7) will easily resolve to the tonic as well, especially if inverted so that the chord's fifth (the key's seventh) is placed in the bass.
The seventh chord is an oddity in the harmonized major scale; it contains both of the "minor third" intervals that are possible in the major scale, and so forms a diminished triad. Add the sixth of the key and it becomes a dominant seventh in the chord, making the full chord half-diminished, a little less dissonant to Western ears by giving it the ii triad's elements, so now the chord can resolve easily to the ii chord by removing the root (the seventh of the key), or directly to the IV chord by converging the seventh and the second into the tonic. The diminished triad itself, though it has that major seventh of the key, actually doesn't resolve well to the tonic directly, because it would require all three notes to move upward; the fewer the notes that have to move to go from one chord to another, the more easily those two chords resolve to each other. However, this progression can work as part of a three-chord progression.
It sounds to me like you would be very interested in learning about modal borrowing and secondary dominant chords. I'll post links about the topics, but I'll give you a general overview.
The major scale and the minor scale are just some of many modes that exist in music.
Let's take the C scale for example. If you start on C and play the C major scale, your playing the C major (ionian) scale. If you start on the D play the C major scale, you play the D dorian scale.
The idea is as follows:
Note because of this many modes are technically the same scale i.e. C major and A minor, but the functionality is different.
The scale for C major and C mixolydian are different and some composers borrow the Bb major chord that is natural to C mixolydian in a C major song. There are many examples of this and here is a way more in depth explanation.
Secondary dominant chords:
The idea is the dominant seventh (V7) is a very strong chord in a key because it wants to go back to the tonic chord(I). A secondary dominant is a dominant chord that doesn't lead to to the tonic chord (I).
A very common use of this in C major would be
I could talk about these topics so much more, but there is a lot to learn and it will take a little bit to comprehend. Just comment if you have any questions about either topic or if I was unclear.
made stupid notation mistake changed
All the information in the earlier answers is relevant generally. There is also the concept of chord substitutions and esp' tritone substitution that's very useful and a backbone in Jazz progressions, and used along with the II-V-I progressions. The tritone sub is used on dominant chords, usually, so G7 can be used instead of Db7 for example, and vice versa, as Db and G are a tritone away from each other.
In Jazz 'color' changes can be made also, and so its common to alter the type of chord. Joe Pass changed alot of chords -whatever they were- to dom7 chords in guitar solos! That takes you 'out of key' straight away of course, but the root note alone is considered enough to harmonize the song. [Usually the tonic chord is not changed in type though, so despite numerous 'key changes' inside a song (equivalent to modal interchange), if the underlying home chord is , say, CMaj7, thats kept as a major chord.]
Specific to the progression asked in the question (D5 Db5 C5 B5): This can actually be analysed as a progression in the Phrygian or Locrian modes, if regarding the B5 chord as 'home', plus the use of a secondary dominant (II-V-I) movement with the C chord being a temporary tonal centre. The power '5' chords used give an unstability and ambiguity -each chord is wanting to go somewhere- even the final B5 chord. Here the D5 chord can be the II chord of the C5 chord (fuller chords would be Dm for the II chord and Cmaj for the temporary I (C) chord). The V chord would be a G7, but here the 3rd and seventh is omitted- would just be using a G5 chord...but rather than use the G7 (or G5 as here) a tritone sub is used..and the tritone of G is Db, so a Db7 can be used (or the 'shortened' version of Db5 as here). This tonally leads to the C5 chord (the temporary I chord), so the next chord is C5. That is a II-V-I movement, using a tritone sub so a II-bII-I movement, common in Jazz.
The next motion goes down to B5. Now that could be a Bm7b5 if a fuller Jazz chord..consistent with a 'Locrian mode' progression...but using that chord is very unstable- it would 'pull to' the CMaj7 chord. So it wouldnt work as a Locrian progression I think (with a 'home chord' being Bm7b5). But if the C5 chord is interpreted as an abridged CMaj7 chord, a movement down half a tone to Bm7 would be a Phrygian progression.
So a 'fuller' equivalent of this progression could be Dm7-Db7-CMaj7-Bm7.
The tritone subs change the II-V-I movements to a descending -by a half tone- sequence, and here theres a final half tone descent to B5.
Bill Evans (the Jazz pianist) noted that any chord type, if moved in equal steps, (whether half tone, one tone, one and half tones..etc etc)...'worked' as a harmonic sequence.
So you could just regard this sequence (D5-Db5-C5-B5) in that light!
Likewise the 'Bill Evans Law' would mean ANY chord type moved equal steps is a viable chord progression. So A5 - B5 - Db5 - Eb5- F5- G5 - A5 is a viable chord progression from that perspective.
The 'local II-V-I', 'tritone subs' plus chord substitutions generally (replacing any chord by another with at least 2 of same notes i it), the 'Bill Evans Law', plus the idea of 'modal interchange'...generally would allow just about any progression you wrote down to be 'understood' from these bases. Whether it sounds nice or whatever..is another thing- and related to personal taste of course.
The short answer here is reharmonization methods. These are different techniques for applying substitutions, key modulations, secondary dominant chords, and other things which help to reinforce the tonality of the original key of your song, while doing it in a more colorful manner. Get a book on reharmonization, such as Reharmonization Techniques by Randy Felts or Volume 3 of my own book.
Re how can D5 Db5 C5 B5 be in any key at all : Key is sometiems inferred from the way the chord structure is arranged over a whole verse, such that a "home" chord to which things want to return is implied -0 eg in the good old 12-bar blues, the sequence sounds like it wants to start again on the initial chord.
However sometimes it's also about rhythm and where things start. For the sequence "D5 Db5 C5 B5", if you play it in a stragh 4/4 repeating pattern, it'll become plain to the earl that the "starting" chord is the D5 and so it becomes the "Key". This is about where the rhythm starts and how other music might be arranged over it like lyrics or an instrumental.
Regarding how to solo over it : You could either just play in D and blow any disagreements your solo has with undrlying chords, or you could play in the chord scale as it changes, or you could play runs or riffs whcih allow for the semitone change in chord, as they change. Or any combination of these..
One thing though - re "how come there can be a chord progression with some chord that doesn't belong in the particular scale" - while reading Stack Exchange lately, there have been quite a few questions on how/why it is that some things work sound-wise when they don't really fit a musical theory pattern. Answer : Either the notion of pattern is wrong or too dictatorial, or us humans love it when rules are broken.
Or a combination of the two :-)