Subject How to return the value of a sub-query as a field in the resulting table
Author cornievs
Please help

I have two tables CLIENTS and POINTS where the CLIENT field in POINTS are linked to the field CODE in CLIENTS.

I need to extract in one query the following data:

CODE from CLIENTS,
NAME from CLIENTS,
SUM(POINTS) where .... from POINTS

Select A.CLIENT, SUM(A.POINTS) FROM POINTS A WHERE A.PROMOTION = 3 GROUP BY A.CLIENT works fine

but when I try

Select A.CLIENT, B.NAME, SUM(A.POINTS) FROM POINTS A JOIN CLIENTS B ON A.CLIENT = B.CODE WHERE A.PROMOTION = 3 GROUP BY A.CLIENT

I get the error "Invalid expression in the select list (not contained in either an aggregate function or the GRUOP by clause)

Further more I would like to sort the result table on A.CLIENT or B.NAME or the value of the Sum() function

Any help would be appreciated.

Tables Info

CREATE TABLE CLIENTS (
CODE BIGINT NOT NULL,
FIRSTNAME VARCHAR(30),
LASTNAME VARCHAR(30),
NAME VARCHAR(60),
TELEPHONE VARCHAR(15),
EMAIL VARCHAR(60),
AREA VARCHAR(15),
POINTS_RECEIVED BIGINT,
POINTS_REDEEMED BIGINT,
POINT_BALANCE BIGINT,
DT_STARTED TIMESTAMP,
DT_LASTVISIT TIMESTAMP,
CARDNO VARCHAR(15)
);

CREATE TABLE POINTS (
CODE BIGINT NOT NULL,
CLIENT BIGINT NOT NULL,
PROMOTION INTEGER,
POINTS BIGINT NOT NULL,
DT TIMESTAMP NOT NULL,
REASON INTEGER NOT NULL
);



__________________
Cornie van Schoor
InfoStar Software
Cel: 082 338 4019
Fax: 086 6000 454
Skype: cornievs
www.infostar.co.za