Click here to Skip to main content
15,894,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
orderdetails 
orderdatailsid | order_master_id branchname category branchid 
1				112				vellore		nad		123
2				112				vellore		hu		123
3				113				chennai		ji		121
4				112				vellore		hi		123	
5				134				tvl			ui		145	
6				134 				tvl		jo		145
7				
masterdetails
ordermasterid    userid
112              12
113		 13
134	         14

SQL
SELECT T.*,S.* FROM
(
  Select TD.category_name,TD.branch_name,TM.created_date,TM.user_id,TD.order_details_id,TD.branch_id
  From tbl_orderdetails TD Inner Join tbl_ordermaster TM ON
    TD.order_master_id = TM.ordermasterid
  Where TM.user_id='12'
) T Inner Join
(
SELECT M.branch_name,Max(M.No_Of_Branch) FROM
  (
    Select T1.branch_name,Count(T1.branch_name) As No_Of_Branch
    From tbl_orderdetails T1 Inner Join tbl_ordermaster T2 ON
         T1.order_master_id = T2.ordermasterid
    Where T2.user_id='12'
    Group By T1.branch_name
  ) M Group By M.branch_name
) S On S.branch_name = T.branch_name


i used this code but not getting appropriate result
Posted
Comments
Magic Wonder 25-Jun-14 1:44am    
Kindly clarify, top 3 Branch Name w.r.t. what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900