Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
SQL
select  * from vOrderDetails D where OrderID = 65
select * from tblOrderReturns R where OrderID = 65



First Table Data

OrderDetailsID OrderID productname

19 65 abc
21 65 ddf
20 65 asdf


Second Table Data


OrderDetailsID OrderID

19 65
21 65


Here I write this query

SQL
select O.OrderID,D.OrderDetailID,D.ProductName,
case when R.OrderDetailID  != D.OrderDetailID then '0'
else '1'
end ReturnItem
From dbo.vOrderDetails D left outer Join tblOrders O On O.OrderID = D.OrderID
left outer join  tblCustomerLogins L On O.CustomerID = L.CustomerID
left outer join tblOrderReturns R on R.OrderID = D.OrderID
Where O.OrderID = 65 And L.SessionID ='8004837C7D62qdSV8'


Now i want to display Three colomn but i get
6 rows
How can i do this?
Posted
Comments
Zoltán Zörgő 23-Jan-15 10:00am    
This is actually a repost of this one. I suggest you continue the topic there.
jaket-cp 23-Jan-15 10:02am    
It looks like a re-post, but the op is asking a different question :)
jaket-cp 23-Jan-15 10:01am    
Have a read of https://msdn.microsoft.com/en-us/library/ms187731.aspx
for examples of how to use the select clause
Shweta N Mishra 23-Jan-15 11:35am    
explain the result you want with data and i guess you are missing a join on OrderDetailID

1 solution

If I understood your question correctly you get too many rows?

The data you provided covers only two of the tables. In your query you have 4 tables. So most likely one of the tables is causing the rows to multiply or you have a problem with the joining fields (missing field for example).

Just guessing based on the names of the tables, could the table tblCustomerLogins cause extra rows?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900