Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT        tb_Ticket.TicketName, tb_Sales.DateDraw, tb_UserManagement.UserName, 
tb_Sales.BillNo, tb_PrizeNumbers.PrizePosition, tb_PrizeNumbers.PrizeNo, 
                         tb_PrizeDetails.Stockist, tb_PrizeDetails.Substockist, tb_PrizeDetails.Agent
FROM            tb_Bill INNER JOIN
                         tb_PrizeDetails INNER JOIN
                         tb_LotteryPrizeDetails ON tb_PrizeDetails.TID = tb_LotteryPrizeDetails.TID INNER JOIN
                         tb_PrizeNumbers ON tb_LotteryPrizeDetails.TID = tb_PrizeNumbers.TID ON 
                         tb_Bill.SerialNo = tb_PrizeNumbers.PrizeNo CROSS JOIN
                         tb_Ticket INNER JOIN
                         tb_Sales ON tb_Ticket.TicketID = tb_Sales.TicketID INNER JOIN
                         tb_UserManagement ON tb_Sales.UserID = tb_UserManagement.UserID INNER JOIN
                         tb_WinningTable ON tb_Ticket.TicketID = tb_WinningTable.TicketID GROUP BY tb_Bill.BillNo


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

this is the error showing.. help me plzzzzzzzzzz

What I have tried:

SQL
SELECT        tb_Ticket.TicketName, tb_Sales.DateDraw, tb_UserManagement.UserName, 
tb_Sales.BillNo, tb_PrizeNumbers.PrizePosition, tb_PrizeNumbers.PrizeNo, 
                         tb_PrizeDetails.Stockist, tb_PrizeDetails.Substockist, tb_PrizeDetails.Agent
FROM            tb_Bill INNER JOIN
                         tb_PrizeDetails INNER JOIN
                         tb_LotteryPrizeDetails ON tb_PrizeDetails.TID = tb_LotteryPrizeDetails.TID INNER JOIN
                         tb_PrizeNumbers ON tb_LotteryPrizeDetails.TID = tb_PrizeNumbers.TID ON 
                         tb_Bill.SerialNo = tb_PrizeNumbers.PrizeNo CROSS JOIN
                         tb_Ticket INNER JOIN
                         tb_Sales ON tb_Ticket.TicketID = tb_Sales.TicketID INNER JOIN
                         tb_UserManagement ON tb_Sales.UserID = tb_UserManagement.UserID INNER JOIN
                         tb_WinningTable ON tb_Ticket.TicketID = tb_WinningTable.TicketID GROUP BY tb_Bill.BillNo


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

this is the error showing.. help me plzzzzzzzzzz
Posted
Updated 28-Mar-16 22:10pm

1 solution

A GROUP BY clause "collapses" a range of rows into a single row with identical values - and you can only return those identical values directly - all other columns from the group of rows can only be returned as an aggregate value - the SUM, the AVERAGE, and so on.
So if you have three rows
ID   Date        Sales
1    2016-01-02  100
2    2016-01-02  200
3    2016-01-02  300
4    2016-01-03  400
5    2016-01-03  500
6    2016-01-03  600
And you GROUP BY Date, then you can't return the Sales value directly because SQL doesn't know which row value to return:
SQL
SELECT Date, Sales FROM MyTable GROUP BY Date

Date        Sales
2016-01-02  ??? Should this be 100, 200, or 300?
2016-01-03  ??? Should this be 400, 500, or 600?
You can return an aggregate value though:
SQL
SELECT Date, SUM(Sales) FROM MyTable GROUP BY Date

Date        Sales
2016-01-02  600
2016-01-03  1500

You are trying to return values which aren't necessarily a single row value because you GROUP BY BillNo so SQL complains.
You need to work out exactly what your data looks like, and what you need to return - and we can;t help you with that, because we have no idea what your data is, much less what you want to select!
 
Share this answer
 
Comments
[no name] 29-Mar-16 9:46am    
Very good Explanation, a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900