Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 other than inner join

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-11-30 : 08:09:40
Sandip writes "If table A contain all Orders and table b cintain all pins
The common field is GWD_ID in both table
But one GWD_ID contain more than one pin

I want to display all columns with that every single order related to which pin ie all Order with pin Columns

Join is not possible because it displays result for every Pin under one unique GW_ID"

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-30 : 09:44:29
I guess.. you can use left outer join.. so that you can get all the records from one table..

Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-01 : 05:47:46
Post some sample data and the result you want

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2005-12-01 : 06:01:34
Go thru this link this will help you alog with examples
http://www.eggheadcafe.com/forums/ForumPost.asp?ID=43474&INTID=9
Go to Top of Page

druer
Constraint Violating Yak Guru

314 Posts

Posted - 2005-12-01 : 09:28:03
The following will show you all of the products ordered for each order, and will sort the results by the OrderId. You can setup the sort as you wish. The Left OUTER JOIN says "if you can't find any products for this order show me the order anyway." [CODE]select Orders.Fieldwhatever, Orders.Fieldwhatever, Products.FieldWhatever
from Orders LEFT OUTER JOIN Products on Orders.GWD_ID = Products.GWD_ID
order by Orders.OrderId [/CODE]If you only want to see the Orders that actually had products you would use the following instead. Notice that the the LEFT OUTER JOIN is replaced by INNER JOIN which says "ignore any orders that don't actually have products):[CODE]select Orders.Fieldwhatever, Orders.Fieldwhatever, Products.FieldWhatever
from Orders INNER JOIN Products on Orders.GWD_ID = Products.GWD_ID
order by Orders.OrderId [/CODE]Not seeing what you did originally my guess is that you simply used both of the tables in the FROM clause without JOIN criteria which would yield what is called a CARTESIAN set, which simply means that for every single order you would also get every single Product as well.[CODE]select Orders.Fieldwhatever, Orders.Fieldwhatever, Products.FieldWhatever
from Orders, Products
order by Orders.OrderId [/CODE]

Go to Top of Page
   

- Advertisement -