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
 General SQL Server Forums
 New to SQL Server Programming
 Select Query - Sql Server 2008- [Need JOIN]

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2009-11-17 : 04:30:36
I have a Query
select sup_ref_no,mpr_no from qotemst where sup_ref_no ='103006'
Getting O/P like..... sup_ref_no mpr_no
103006 32
103006 32

Good. No problem. Also I have a Query
select mpr_no,mpr_date from mprmst where mpr_no ='32'
Getting O/P like..... mpr_no mpr_date
32 2009-10-15 00:00:00:000
32 2009-10-15 00:00:00:000

Good No problem. Also I have a Query
select sup_ref_no,mpr_no from qotemst where mpr_no ='32'
Getting O/P like..... sup_ref_no mpr_no
1551 32
1551 32
103006 32
103006 32
Good No problem. Also I have a Query

----------------------------------------------
Select q.sup_ref_no,q.item_code,q.mpr_no,m.mpr_date from qotemst q,mprmst m where q.sup_ref_no='103006' and m.mpr_no=q.mpr_no
or
Select q.sup_ref_no,q.item_code,m.mpr_no,m.mpr_date from qotemst q,mprmst m where q.sup_ref_no='103006' and m.mpr_no=q.mpr_no

Getting O/P like.....
sup_ref_no item_code mpr_no mpr_date
103006 SQUAWAS1 32 2009-10-15 00:00:00.000
103006 SQUAWAS2 32 2009-10-15 00:00:00.000
103006 SQUAWAS1 32 2009-10-15 00:00:00.000
103006 SQUAWAS2 32 2009-10-15 00:00:00.000

Doubling Problem, So how to solve it... Any joins?

Any Ideas...Thanks


Paramu @ PARANTHAMAN

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-11-17 : 07:21:24
try using the FROM [table1] JOIN [table2] ON syntax instead of FROM [table1,table2]. This makes it MUCH easier to read and debug.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-11-17 : 07:46:12
there are
- 2 records in qotemst with mpr_no = 32
and
- 2 records in mprmst with mpr_no = 32

so when you join these 2 tables together you will get 4 records. Unless you have another column in the join condition


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-11-18 : 00:30:50
I Get Cleared, Thanks Khtan & DonAtWork

Paramu @ PARANTHAMAN
Go to Top of Page
   

- Advertisement -