Link to home
Start Free TrialLog in
Avatar of Millkind
MillkindFlag for Afghanistan

asked on

Sql Join Statement

I want to combine the two select statements and use the output to insert into another table.
The following are all three individually.


select tblStudent.dIDNumber,tblStudent.lLostCardIdentifier from tblStudent where tblStudent.lMealPlan between 200 and 297 or tblStudent.dIDNumber in (16734300,43384500)

select tblEvents.achEventName,tblEvents.achRemoveDate,bGeneralAccess,tblEvents.lEventNumber from tblEvents where tblEvents.lEventNumber = 601

insert into tblStudentEvents (dIDNumber,lLostCardIdentifier,lEventNumber,lTickets,achEventName,achRemoveDate,bGeneralAccess)
values (tblstudent.dIDNumber,tblstudent.lLostCardIdentifier,tblevents.lEventNumber,1,tblevents.achEventName,tblevents.achEventName,tblevents.bGeneralAccess)
Avatar of oleggold
oleggold
Flag of United States of America image

insert into tblStudentEvents
select tblStudent.dIDNumber,tblStudent.lLostCardIdentifier from tblStudent where tblStudent.lMealPlan between 200 and 297 or tblStudent.dIDNumber in (16734300,43384500)
You need to use insert as select combination
insert as select combination:
insert into tblStudentEvents 
select tblStudent.dIDNumber,tblStudent.lLostCardIdentifier from tblStudent where tblStudent.lMealPlan between 200 and 297 or tblStudent.dIDNumber in (16734300,43384500) join
(select tblEvents.achEventName,tblEvents.achRemoveDate,bGeneralAccess,tblEvents.lEventNumber from tblEvents where tblEvents.lEventNumber = 601) on ...

Open in new window

Avatar of Millkind

ASKER

That the problem there is no on, there is not unique id between them.
as per abov e You need something to join on between students and events , please paste the structure of both tables if You need help identifying what attribute is used to join those 2 tables.
Avatar of Guy Hengel [angelIII / a3]
I guess s that both SELECT return one row.
You can do
Insert into ...
Select...
From table1 , table2
Where...
No one will return multiple rows the other will return only one.  I think im starting to see the problems here.  For each return of ID and LostCardID I want it to use the same line of
tblEvents.achEventName,tblEvents.achRemoveDate,bGeneralAccess,tblEvents.lEventNumber from tblEvents where tblEvents.lEventNumber = 601) for each one. it inserts.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect. And the explanation link was superb.