I need to retrieve all the records in one table, and the count of corresponding records.THere are immidiatly 2 ways to do thisSelect *,(Select count(*) from T_Relation aa where aa.RelationID = a.RelationID)fromT_Main a
Select a.f1,a.f2,a.f3,a.f4,a.f5,a.RelationID,Count(*)fromT_Main aInner joinT_Relation bon a.RelationID = b.RelationIDgroup by a.f1,a.f2,a.f3,a.f4,a.f5,a.RelationID
Under the assumption that table main has proper index's and 50,000 records and table Relation has 500,000 records and proper index's, which is generally a better practice.I am asking because I need to write about 15 similar queries, and want to keep them all the same format.Thanks