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

Insert data from two tables to another one - join problem

Status
Not open for further replies.

shyamal

Programmer
Aug 14, 2000
79
US
I am attempting to insert into a destination table from two source tables in the same database with certain criteria.

Table Names Table fields
SRC: Table1 - (fldintkey,fldint1,fldchar) - all null
SRC: Table2 - (fldintkey,fldint1,fldchar) - all null
Dst: Table_Dst -(fldintkey,fldint1,fldchar) - all null

Data: (fldintkey,fldint1,fldchar)
Table1: 1,1,'test'
Table2: 2,2,'test'
Table3: needs both rows from the above table where
fldchar = 'test'

The insert\join which does not work:

INSERT INTO Table3(FLDINTKEY,FLDINT1,FLDCHAR)
SELECT A.FLDINTKEY,A.FLDINT1,A.FLDCHAR,
B.FLDINTKEY,B.FLDINT1,B.FLDCHAR
FROM Table1 A,Table2 B
WHERE A.FLDCHAR = 'TEST'
AND B.FLDCHAR = 'TEST'

Thanks in advance.
 
You cannot insert 6 fields (via the SELECT) into a 3 field table.

If there's no JOIN field between the 2 tables, then have 2 separate SELECTs with a UNION between them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top