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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TWO FIELD FROM TWO TABLE IN ONE TABLE WITH SQL 2

Status
Not open for further replies.

Gert

Programmer
Apr 9, 2000
240
DO
HI ALL,
I GOT TWO TABLE WITH TO DIFFERENT FIELD ON EACH ONE, WHAT I NEET IS TO PUT BOTH FIELD IN JUST ONE TABLE, EXAMPLE:

SELE TBLVEND.CODVEN, TBLVEN.DESVEN,TBLVEND.FECVEN,TBLART.CODART, TBLART.DESART,TBLART.FEVEN;
FROM TBLVEND, TBLART;
WHERE TBLVEND.FECVEN>=mfrom .and. TBLVEND.FECVEN<=mhast
GROUP BY TBLVEND.CODVEN;
INTO CURSOR CURTOT


COD DESCRIP DATE
1 MONT
2 DISK
3 MOUSE
4 CAMERA
5 ESTATION
6 FLAG
7 KEYBOARD
8 BRIDGE
9 PROCCESOR
 
WHEN I MADE THE SQL A FIELD IS CREATE FOR EACH FIELD ON THE SQL OPTION:

THIS IS WHAT APPEAR ON THE RESULT TABLE, EXAMPLE:

CODVEN
DESVEN
FECVEN_A
CODART
DESART
FECVEN_B
::: and i only need 3 fields ::::::
COD
DESCRIP
DATE



 
Hi,

If TBLVEND has the same structure as TBLART you can use the UNION clause like:

SELECT codven, desven, fecven ;
FROM tblvend ;
WHERE fecven>=mfrom and fecven<=mhast ;
UNION ;
SELECT codart, desart, fecven ;
FROM tblart ;
ORDER by 1
 
Gert,
Ah! You can also add the AS clause to get the field names you want (Note: 'Date' is a not a good idea!) :
Code:
SELECT codven AS COD, desven AS DESCRIP, fecven AS DATE;
 FROM tblvend ;
 WHERE BETWEEN(fecven,mfrom,mhast) ;
UNION ;
 SELECT codart, desart, fecven ;
  FROM tblart ;
 ORDER by 1
Rick
 
You are welcome.

If TBLVEND has the same structure as TBLART you can use the UNION clause

Actually, the fields in both SELECTs must have the same data type and width, not the tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top