问题描述:

I have data in two tables that i want to get into a view to then be able to do reporting on and having trouble as only some of the records in the first table have records in the second table.

The data is ranges for a product.

For example I have 2 options the first has 6 ranges of pricing, 3 are stored in table A and 3 in table B linked by the ID of the record in table A. The second has only 3 ranges that are in table A so no record is created in table B for this product.

When I try to do a create view and include the details from the second table I only get the details for the first option and not the second as it is excluding this because there is no record in the second table.

How do I over come this?

TableP1 TableP2

Product_id Unit Range 1 Range 2 Range 3 TableP1_ID Range 4 Range 5 Range 6 TableP1_ID

1 Person 20 18 16 1 14 12 10 1

2 Person 25 22 2

not sure if the above makes sense.

网友答案:

Can you not have two queries and UNION the results together in your VIEW code?

Something like:

CREATE myView 
AS

SELECT X,
       Y
FROM   Table1

UNION

SELECT X,
       Y
FROM   Table2;
相关阅读:
Top