How can i get data from entity with or without

I have two entities. [Product] and [OrderDetails]

i want to show all record of [Products]. and I want from the [OrderDetails] the details of an order to show same order details of certain order.

I did this but I don't have the correct data I want:


Hi K A,

you need a join condition instead of a filter condition.  

SQL server executes a query in several steps : join conditions are executed on the to be joined table before producing the result table of the join, filter conditions are executed on the result table of the join, reducing the result set after the join.

So remove the filter, and add it as a join condition

Dorine

Hello,

You can do that using an sql query.

Do an Union where your first Select will return all products and the second select will return the product associated with your order detail.


Select {product}.[id],

X

From {Product}

UNION

Select {Product}.[id],

X

From {Product}

Inner Join {orderdetails} on ...

Where {orderdetails}.[id] = @id 


If the orderdetail could have no product associate change the second select. You should pay attention that the number of attributes in the selects should be the same and match with the output strucuture.

If this is not a solution, please provide more details about what you intend.

Hi K A, 
It seems like you want to achieve 2 things, 
1) i want to show all record of [Products]. 
2) I want from the [OrderDetails] the details of an order to show same order details of certain order. 
Can you explain the second part?


or you can also give some example like the one below, its just something to show what is your expected end result, so that a solution can be suggested by the community members. 

thanks for the tips!

i have two tables with data:

Hi K A, 
Please try this below aggregate

Hi K A,

you need a join condition instead of a filter condition.  

SQL server executes a query in several steps : join conditions are executed on the to be joined table before producing the result table of the join, filter conditions are executed on the result table of the join, reducing the result set after the join.

So remove the filter, and add it as a join condition

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.