Space–time network coding has recently been used in cooperative communication to mitigate the problem of transmission delay in wireless systems as well as handle the issue of imperfect synchronization. However, using all relays for transmission to forward the network coded signals can still cause delay in such networks, resulting in lower throughput. In this paper, we propose a Q-learning based relay selection algorithm (QL-RSA) that maximizes the total capacity of the network by learning the cooperative network environment. QL-RSA is distributed, as each source is capable of self-learning in order to select the optimal relays separately, without exchanging information with the other source nodes. Similarly, the proposed algorithm is adaptive as it can efficiently learn the network under varying channel conditions to select the relays. We choose different sets of relays and study the impact of relay selection on the performance in terms of the throughput and outage using QL-RSA.