2

I am getting an an error:

Column 'Transaction_Master.Tranaction_Slno' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

select TM.Tranaction_Slno,Container_Number,count(TM.CFS_Id), Container_Size,CFM.CFS_Name,
TD.Container_Size as Size,
Read_Time,gate,Location from Transaction_Master TM
inner join Transaction_Data TD on TD.Tranaction_Slno = TM.Tranaction_Slno
inner join Transaction_Track TT on TT.Transaction_Slno = TM.Tranaction_Slno
inner join CFSMaster CFM on TM.CFS_ID = CFM.CFS_Id
where CFM.CreatedOn='2015-12-02 02:06:30.000'
group by CFM.CFS_Name
Dale K
  • 25,246
  • 15
  • 42
  • 71
Niranjan S
  • 132
  • 9
  • So what do you want to do? We probably need to see some sample data and expected results. When you group by, you can only select the columns you are grouping by, any others have to be aggregated in some way. – Dale K Feb 21 '19 at 05:53
  • Possible duplicate of [Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause](https://stackoverflow.com/questions/25742351/column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggre) – Dale K Feb 21 '19 at 05:54
  • @Dale Burrell I want a count of CFS_Id and some columns from the tables of Transaction_Master,Transaction_Data,Transaction_Track with group by CFS_Name from the table CFSMaster – Niranjan S Feb 21 '19 at 06:01
  • Please update you question directly - don't add clarifications in the comments. Please include sample data - although the duplicate question should clarify it for you. – Dale K Feb 21 '19 at 06:02
  • Do you need count of CFS_ID for each CFS_name and other columns from Transaction_Master,Transaction_Data,Transaction_Track – Vijiy Feb 21 '19 at 06:07

2 Answers2

0

when you use aggregate function in your query in that case you have to add your all selection column in group by except aggregated column

select TM.Tranaction_Slno,Container_Number,count(TM.CFS_Id), Container_Size,CFM.CFS_Name,
TD.Container_Size as Size,
Read_Time,gate,Location from Transaction_Master TM
inner join Transaction_Data TD on TD.Tranaction_Slno = TM.Tranaction_Slno
inner join Transaction_Track TT on TT.Transaction_Slno = TM.Tranaction_Slno
inner join CFSMaster CFM on TM.CFS_ID = CFM.CFS_Id
where CFM.CreatedOn='2015-12-02 02:06:30.000'
group by CFM.CFS_Name,TM.Tranaction_Slno,Container_Number,Container_Size,
TD.Container_Size,Read_Time,gate,Location
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
0

All the columns which you want to select should be in the group by clause or part of the aggregate function. The error message you are getting also saying the same thing. You can run below query.

  select TM.Tranaction_Slno,Container_Number,count(TM.CFS_Id), Container_Size,CFM.CFS_Name,
        TD.Container_Size as Size,
        Read_Time,gate,Location from Transaction_Master TM
        inner join Transaction_Data TD on TD.Tranaction_Slno = TM.Tranaction_Slno
        inner join Transaction_Track TT on TT.Transaction_Slno = TM.Tranaction_Slno
        inner join CFSMaster CFM on TM.CFS_ID = CFM.CFS_Id
        where CFM.CreatedOn='2015-12-02 02:06:30.000'
 group by CFM.CFS_Name,TM.Tranaction_Slno,Container_Number,Container_Size
Mukesh Arora
  • 1,763
  • 2
  • 8
  • 19