Link to home
Start Free TrialLog in
Avatar of splanton
splantonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL Server 2008 combining a query.

Frirst: A bit of background...

I have two tables related one to many with a third as a resolving table :

WasteType
WasteTyperesolve (resolving table)
WasteSubtype

They look like this:

WasteType
Id      Description
1      Cardboard
2      Paper
3      Cans
4      General

WasteSubType
Id      Description
1      Cardboard
2      Paper

WasteSubTypeResolve
Id      ParentId      ChildId
1      4       1
2      4      2

The following query combines the two tables, ignoring any WasteType records that have WasteSubtypes:

SELECT [Description] FROM [WasteType]
WHERE [WasteTypeId] NOT IN (SELECT [WasteTypeId] FROM [WasteSubTypeResolve])
UNION SELECT [Description] FROM [WasteSubType] ORDER BY [Description]

It would produce:

Cardboard
Paper
Cans

The question...

I need to combine this query with another one.

The second query is

SELECT Id,Description FROM Site

and returns:
Id      SiteDesc
1      London
2      Brighton
3      Manchester


I need to combine these queries to show the following:

Id      SiteDesc      WasteStreamDesc
1      London      Cardboard
1      London      Paper
1      London      Cans
2      Brighton      Cardboard
2      Brighton      Paper
2      Brighton      Cans
3      Manchester      Cardboard
3      Manchester      Paper
3      Manchester      Cans

I did post a similar question earlier in the day about combining the results of two tables but that was BEFORE I was informed hat the first query was a little more complicated that I had originally been led to believe.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America 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
Avatar of splanton

ASKER

A very clear,concise more importantly working) solution. Many thanks.