Investigation of light and heavy tetraquark candidates using lattice QCD