Question Locked

SQL join

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Please how can I combine these select statements using a join and then insert the result into a new table.

SELECT
team, SUM(operations) as Operations_Completed
from Table1
where team in ('bristol', 'leeds', 'newcastle','north west')
group by team

SELECT

team,
SUM(sales) as Packsales,
COUNT(*) as contacts,
COUNT(CASE WHEN brandtype = 'SOB' THEN brandtype ELSE NULL END) as EffectiveContacts

from Table2
where team not in ('MANCHESTER GREATER','MANCHESTER CITY')
group by team

2 replies

by tony hopkinson

Create two temporary tables and select into them, then it should be just a join on team. Can't tell from you request whether you want an inner or outer (left or right) though.

The other way is a bit more sneaky
and uses the following syntax
select ....
Join (select....) dummyTableName On Table1.Team = dummyTableName.Team

Just prefix the either of the above with Insert into SomeTable if the table is alreday defined, or use select Into if not.

HtHs

This discussion is closed to new replies.