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 statement

Author  Topic 

asm
Posting Yak Master

140 Posts

Posted - 2007-02-19 : 07:39:32
Hi

I have two table One- Product Two- ProductRate
I want to retrive the data from both table.
But the both table have different columns--
I am using two query to get the result but wanted do this
in single query

query one-
Select PL.PriceListNo, PL.Productcode, PL.PriceRate, PM.Description from productRate PL inner Join Product PM On PL.Productcode = PM.ProductCode

query two-
Select Productcode, Description from product where productcode not in (select productcode from productrate)

thanks

asm

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-19 : 07:41:40
Select PL.PriceListNo, PL.Productcode, PL.PriceRate, PM.Description from productRate PL inner Join Product PM On PL.Productcode = PM.ProductCode
UNION ALL
Select null, pm.Productcode, null, pm.Description from product pm left join productrate pl on PL.Productcode = PM.ProductCode where pl.productrate is null


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-19 : 07:59:15
why not left join ?

select p.ProductCode, p.Description, r.PriceListNo, r.PriceRate
from product p left join productrate r
on p.ProductCode = r.ProductCode



KH

Go to Top of Page
   

- Advertisement -