Related resources for sub query in SQL