| Author |
Topic |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 05:59:39
|
| How to join these queries without union all select f.mobid, f.merchant, f.pricefrom ( select mobid, min(price) as minprice from tbl_merchant group by mobid ) as x inner join tbl_merchant as f on f.mobid = x.mobid and f.price = x.minprice order by mobid select f.mobid, f.merchant, f.pricefrom ( select mobid, max(price) as minprice from tbl_merchant group by mobid) as x inner join tbl_merchant as f on f.mobid = x.mobid and f.price = x.minprice order by mobidVery urgent!Tnx in advance |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-08-24 : 06:05:09
|
| Do you want the result of the two queries merged?MadhivananFailing to plan is Planning to fail |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:11:47
|
| Ya sure ..I need answer in single table |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-08-24 : 06:17:41
|
quote: Originally posted by jafrywilson Ya sure ..I need answer in single table
Both queries are same. Why do you want duplicate results?MadhivananFailing to plan is Planning to fail |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:24:05
|
quote: Originally posted by madhivanan
quote: Originally posted by jafrywilson Ya sure ..I need answer in single table
Both queries are same. Why do you want duplicate results?MadhivananFailing to plan is Planning to fail
No that are not same first query returns minimum value and the nxt return maximum value |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:26:12
|
| I need to show both the values min price & max price in 2 columns and mobid,merchant in nxt 2 columns |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:27:58
|
| My o/p must like this Mobid|Merchant|Min_price|Max_price |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-08-24 : 06:31:59
|
| You dont need two statements. This is enoughselect f.mobid, f.merchant, x.minprice, x.maxpricefrom (select mobid, min(price) as minprice, max(price) as maxpricefrom tbl_merchant group by mobid ) as x inner join tbl_merchant as f on f.mobid = x.mobid and f.price = x.minprice order by mobid MadhivananFailing to plan is Planning to fail |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:43:22
|
quote: Originally posted by madhivanan You dont need two statements. This is enoughselect f.mobid, f.merchant, x.minprice, x.maxpricefrom (select mobid, min(price) as minprice, max(price) as maxpricefrom tbl_merchant group by mobid ) as x inner join tbl_merchant as f on f.mobid = x.mobid and f.price = x.minprice order by mobid MadhivananFailing to plan is Planning to fail
It s not working because only one column price is in my table in that column find the min and max value..Ur answer gives this errorMsg 207, Level 16, State 1, Line 1Invalid column name 'minprice'.Msg 207, Level 16, State 1, Line 1Invalid column name 'maxprice'. |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:45:22
|
| sorry sir.. It is my mistake...Ur query works ..Thanks a lot.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-08-24 : 06:47:06
|
quote: Originally posted by jafrywilson sorry sir.. It is my mistake...Ur query works ..Thanks a lot..
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-24 : 06:55:59
|
| how to show min_price merchant name and Max price merchant name in the same table ..How to select it ... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-08-24 : 08:24:15
|
| Which version of SQL Server are you using?MadhivananFailing to plan is Planning to fail |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-08-25 : 06:58:06
|
| i am using sql server 2005.. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|