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.
| Author |
Topic |
|
sachin.hingole
Starting Member
15 Posts |
Posted - 2009-05-04 : 06:25:37
|
| Hi,I have 2 tables1 is products and 2 is ProductCategoryI want those products having the comman product categoriesProduct tableProductID ProductName1 P12 P23 P34 P4ProudctCategory TableProductCategoryID ProductCategoryname ProductID 1 P1C 12 P1C 23 P1C 34 P2C 15 P2C 26 P3C 27 P3C 38 P4C 3OutputsubCat ProductidP1C 1P2C 1P1C 2P2C 2P3C 2P3C 3P4C 3P1C 3Thanks in advanceSachin Hingoleedit: moved to proper forum |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-05-04 : 06:29:44
|
| Will u put some Sample data and expected output!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-04 : 09:32:27
|
| select ProductCategoryname, ProductID from ProudctCategory as pcinner join Product as p on p.productid = pc.productid |
 |
|
|
malaytech2008
Yak Posting Veteran
95 Posts |
Posted - 2009-05-04 : 13:59:11
|
| select a.ProductCategoryname, a.ProductID from Product pinner join(select ProductCategoryID,ProductCategoryname,ProductID from ProudctCategory where ProductCategoryID in(select ProductCategoryID from ProudctCategory group by ProductCategoryID having count(*)>1)) a on p.ProductID=a.ProductIDorder by a.ProductIDorselect a.ProductCategoryname, a.ProductID from Product pinner join(select ProductCategoryID,ProductCategoryname,ProductID from ProudctCategory where ProductCategoryID in(select ProductCategoryID from ProudctCategory group by ProductCategoryID having count(*)>0)) a on p.ProductID=a.ProductIDorder by a.ProductIDmalay |
 |
|
|
|
|
|