Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

We have a number of reports having two-three fields that are always displayed in a particular order.

For convenience, the DB architect has designed a master ordering table that saves the ordering of the 2-3 fields with numerical values assigned to them. i.e.
Ordering_Master
Group1 	Order1	        Group2		Order2
PAM	1	 	HNWI		1
PAM	1	 	Hedge Funds	2
PAM	1	 	PFs		3
PAM	1	 	ETFs		4
PIM	1	 	Pvt Insts	1
PIM	1	 	Banks		2
PIM	1	 	Trusts		3

Now, we have another table that is used for driving almost all of our reports i.e. the
Transaction_Master
Id	      Name	   Record_Type	Close_Date	Status	Role__c	Group1 Group2       
a0L7000000Cyk0fEAB	84001166 	Open Opportunities	00:00.0	 Forecast	Sales - Gov - West & MidWest	PAM	ETFs
a0L7000000Cyk0gEAB	84001167	 Open Opportunities	00:00.0	 Forecast	Sales - Gov - West & MidWest	PAM	 PFs
a0L7000000Cyk0hEAB	84001168	 Open Opportunities	00:00.0	 Forecast	Sales - Gov - West & MidWest	PAM	 HNWI
a0L7000000A1kEeEAJ	82949995	 Open Opportunities	00:00.0	 Forecast	Business - Index and Analytics	PIM	Banks
a0L7000000AusDkEAJ	83431781	 Open Opportunities	00:00.0	 Forecast	Sales - Gov - Boston	PAM	HNWI

Now, I am trying to make a join of the above 2 tables i.e. of the Transaction_Master & Ordering_Master tables on the Group1 & Group2 fields, however I am getting repeating rows.

My aim to join these two tables & get the Order1 & Order2 columns from the Ordering_Master table and then sort the resultset by the Order1 and then the Order2 column i.e.
Order By Order1 , Order2

Any help would be much appreciated.

Thanks,
Aryan.
Posted
Updated 24-Oct-12 4:54am
v2
Comments
Maciej Los 24-Oct-12 14:21pm    
Show us what you have done till now...
Aadhar Joshi 26-Oct-12 6:23am    
Please put here your query

SQL
select order1, order2
from transaction_Master tm
    Join ordering_master om ON tm.group_1= om.group1 and tm.group_2=om.group2
order by order1, order2
 
Share this answer
 
v2
If you are getting repeating rows, just add a DISTINCT clause in. Or am I missing something in your question?
 
Share this answer
 
Distinct is not recommend always.

Just use this query

SQL
select order1, order2
from transaction_Master tm
    Join ordering_master om ON tm.group_1= om.group1 and tm.group_2=om.group2
order by order1, order2
 
Share this answer
 

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