Question

Locked

SQL join

By skatula ·
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

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Join wise there are two ways

by Tony Hopkinson In reply to SQL join

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

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums