Groups | Blog | Home
all groups > sql server misc > august 2005 >

sql server misc : Assistance with a query


s commar
8/7/2005 6:45:19 AM
I have 2 tables POheader and POline. I am running the following SQL
statement but am getting 2 records where as I should only be getting one.
Could someone please assist.
s_commar@hotmail.com



select POheader.ponbr from POheader inner join POline on POheader.Ponbr =
POline.Ponbr and POline.ponbr
= 16916;


I should just be getting one record but I get 2 records. Could someone
advise as to what I am doing wrong.
Thanks

s_commar@hotmail.com

Roji. P. Thomas
8/7/2005 12:53:47 PM
Its hard to comment without seeing DDL+Sample data. My best
guess is that your POline table has 2 matching rows. If you dont want to
reference any columns from the POnline table in the final output,
you can probably rewrite your query like

Select POheader.ponbr from POheader
WHERE EXISTS(
SELECT 1 FROM POline WHERE POheader.Ponbr = POline.Ponbr
AND POline.ponbr = 16916)

--
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com


[quoted text, click to view]

AddThis Social Bookmark Button