Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL and union

Status
Not open for further replies.

pudarda

Technical User
Feb 9, 2005
8
AR
I have the following sentence SQL

SELECT GRUPO,numero, NOMBRE, DOMICI, TELEFONO,;
ZONA, PLAN, CUOTA;
FROM SOCIOS;
WHERE XC_COB = "S";
UNION;
SELECT GRUPO,NUMERO, NOMBRE, DOMICI, TELEFONO,;
ZONA, PLAN, CUOTA;
FROM BAJAS;
WHERE XC_COB = "S";
INTO CURSOR DEPASO

the same one gives me for example

> 0012 1 ...
> 0012 2...
> 0012 3 the first
>
> 1212 8
> 3212 1
> 3212 2 the second

but I need that alone me of one for group but with the minor I number since
if I group them she gives that of adult I number that is to say

> 0012 1
> 1212 8
> 3212 1

as I obtain this I finish result?
 
Hi,

Try adding the MIN() function to your field "numero" and a GROUP BY clause.

SELECT GRUPO, min(numero), NOMBRE, DOMICI, TELEFONO,;
ZONA, PLAN, CUOTA;
FROM SOCIOS;
WHERE XC_COB = "S";
GROUP BY grupo;
UNION;
SELECT GRUPO, min(NUMERO), NOMBRE, DOMICI, TELEFONO,;
ZONA, PLAN, CUOTA;
FROM BAJAS;
WHERE XC_COB = "S";
GROUP BY grupo;
INTO CURSOR DEPASO
 
SELECT GRUPO, min(numero), NOMBRE, DOMICI, TELEFONO, ZONA, PLAN, CUOTA;
GROUP BY grupo;

More info is needed. You don't include non agregated fields in the SELECT that don't also occur in GROUP BY unless you know something special about the data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top