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 |
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2009-09-10 : 17:19:03
|
| Hi.I have 2 tables:tbl_producttbl_configthe join betwen them are 1 to nmeans there are only one product_id on tbl_product but we have several product_id's(FK) on tbl_configthe PK for tbl_product is product_idthe PK for tbl_config is catIDI need to get catID's on tbl_config which have the lowest product_price on tbl_product.I wrote:SELECT MIN(dbo.tbl_product.product_price) AS price, dbo.tbl_config.product_idFROM dbo.tbl_product INNER JOIN dbo.tbl_config ON dbo.tbl_product.product_id = dbo.tbl_config.product_idGROUP BY dbo.tbl_config.product_idbut when I added the catID field it gave me all the product_id'sthank u so much for yr help |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-09-11 : 02:30:17
|
| try any one of theseSELECT MIN(p.product_price)OVER(PARTITION BY p.product_id) AS price, p.product_id, C.CatidFROM dbo.tbl_product p INNER JOINdbo.tbl_config c ON p.product_id = c.product_idselect c.catid,p.product_id,p.pricefrom tbl_config cinner join (select MIN(product_price) AS price, product_id FROM dbo.tbl_product group by product_id ) p on p.product_id = c.product_id |
 |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-09-11 : 03:30:49
|
| Can you give some sample data?Rahul Shinde |
 |
|
|
|
|
|