Author |
Topic |
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-05 : 11:36:01
|
Hi,This is the result set:16 D1 179 521272 1922 D1 150 NULL 92922 D2 151.5 1020005 93622 D3 174.95 NULL 2822 D1 178 NULL 3122 D4 182 NULL 2922 D6 190 481315 93522 D4 195 1E770410 93023 D5 30 C4844A 390824 D5 30 AC4836AN 390925 D5 30 C4837AN 391026 D5 30 C4838AN 391129 D7 90 544899 145429 D3 91.25 269-05584 146129 D1 96 330507 139729 D4 97 Email 183829 D6 110 321356 1462Expected result:16 D1 179 521272 1922 D1 150 NULL 92923 D5 30 C4844A 390824 D5 30 AC4836AN 390925 D5 30 C4837AN 391026 D5 30 C4838AN 391129 D7 90 544899 1454The query i'm usingSELECT DISTINCT dbo.tblItems.cntProduct, dbo.tblVendor.VendorName, dbo.tblItemsPricing.Price, dbo.tblItemsPricing.strVendorPartNumber, dbo.tblItemsPricing.cntQuoteFROM dbo.tblItems INNER JOIN dbo.tblItemsPricing ON dbo.tblItemsPricing.cntProduct = dbo.tblItems.cntProduct INNER JOIN dbo.tblVendor ON dbo.tblItemsPricing.cntVendor = dbo.tblVendor.cntVendorORDER BY dbo.tblItems.cntProduct, dbo.tblItemsPricing.PricePlease let me know how i can achieve the above expected result. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 11:44:16
|
do you have a unique valued column in table to determine the order? |
|
|
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-05 : 12:11:28
|
yes: dbo.tblItemsPricing.cntQuote is the unique id |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 12:15:41
|
then its easySELECT dbo.tblItems.cntProduct, dbo.tblVendor.VendorName, dbo.tblItemsPricing.Price, dbo.tblItemsPricing.strVendorPartNumber, dbo.tblItemsPricing.cntQuoteFROM dbo.tblItems INNER JOIN dbo.tblItemsPricing ON dbo.tblItemsPricing.cntProduct = dbo.tblItems.cntProductINNER JOIN (SELECT cntProduct,MIN(cntQuote) AS Start FROM dbo.tblItemsPricing GROUP BY cntProduct) pON p.cntProduct=dbo.tblItems.cntProduct AND p.Start=dbo.tblItemsPricing.cntQuoteINNER JOIN dbo.tblVendor ON dbo.tblItemsPricing.cntVendor = dbo.tblVendor.cntVendorORDER BY dbo.tblItems.cntProduct, dbo.tblItemsPricing.Price |
|
|
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-05 : 12:27:28
|
Thanks for the quick reply. But, sorry I need to have the price as well minimum. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 12:32:58
|
[code]SELECT dbo.tblItems.cntProduct, dbo.tblVendor.VendorName, dbo.tblItemsPricing.Price, dbo.tblItemsPricing.strVendorPartNumber, dbo.tblItemsPricing.cntQuoteFROM dbo.tblItems INNER JOIN dbo.tblItemsPricing ON dbo.tblItemsPricing.cntProduct = dbo.tblItems.cntProductINNER JOIN (SELECT cntProduct,MIN(Price) AS Start FROM dbo.tblItemsPricing GROUP BY cntProduct) pON p.cntProduct=dbo.tblItems.cntProduct AND p.Start=dbo.tblItemsPricing.PriceINNER JOIN dbo.tblVendor ON dbo.tblItemsPricing.cntVendor = dbo.tblVendor.cntVendorORDER BY dbo.tblItems.cntProduct, dbo.tblItemsPricing.Price [/code] |
|
|
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-05 : 12:40:40
|
Thanx a lot. You are really great. Mimimal input maximum benefit. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 12:41:43
|
welcome |
|
|
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-05 : 13:33:06
|
Hi,when i ran the query on my whole db. I found certain records are repetitive, meaning I see more than one cntProduct, which is suppose to be unique for the returned result set. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 13:36:35
|
quote: Originally posted by naveenbalraj Hi,when i ran the query on my whole db. I found certain records are repetitive, meaning I see more than one cntProduct, which is suppose to be unique for the returned result set.
can be either because you've two records with same min price in tblItemsPricing or multiple records in tblVendor for same product |
|
|
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-05 : 14:21:20
|
yes, the price is the same. i was to mention in my prev reply.How can the query be modified to pick any one? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-06 : 06:23:03
|
[code]SELECT dbo.tblItems.cntProduct, dbo.tblVendor.VendorName, dbo.tblItemsPricing.Price, dbo.tblItemsPricing.strVendorPartNumber, dbo.tblItemsPricing.cntQuoteFROM dbo.tblItems INNER JOIN dbo.tblItemsPricing ON dbo.tblItemsPricing.cntProduct = dbo.tblItems.cntProductINNER JOIN (SELECT cntProduct,MIN(Price) AS Start FROM dbo.tblItemsPricing GROUP BY cntProduct) pON p.cntProduct=dbo.tblItems.cntProduct AND p.Start=dbo.tblItemsPricing.PriceINNER JOIN (SELECT cntProduct,Price,MIN(cntQuote) AS Start AS Start FROM dbo.tblItemsPricing GROUP BY cntProduct,Price) p1ON p1.cntProduct=dbo.tblItems.cntProduct AND p1.Price=dbo.tblItemsPricing.Price AND p1.Start = dbo.tblItemsPricing.cntQuoteINNER JOIN dbo.tblVendor ON dbo.tblItemsPricing.cntVendor = dbo.tblVendor.cntVendorORDER BY dbo.tblItems.cntProduct, dbo.tblItemsPricing.Price [/code] |
|
|
naveenbalraj
Starting Member
18 Posts |
Posted - 2010-02-06 : 11:39:33
|
Thanks a lot. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-06 : 11:41:37
|
welcome |
|
|
|