sql - Unique Join: 2 Primary Keys to one column -


The problem I have is working with 3 table customers, purchases and workflow.

Customer ID is the primary key for the customer table and a 3 digit INT EG. 123

The primary key for the table purchased is an 8 digit INT. EG 12345678

The details of what the workflow is going on at the time of user workflow. Depending on the job it may vary, it may look like this.

  WFID EntityID type ref 771 123 customer 1 772 12345678 purchase 2 773 124 customer 1 774 125 customer 1 775 12,345,679 purchase 2  

for these 2 tables The primary key has been mixed into a single unit ID column and I am having difficulty in getting involved in it, I have been able to join a case statement after this (ON Workflow.EntityID =) that looks like this. Workflow.EntityID =) Case when referee = 1 then buy customer.customerID when ref = 2 then buy .purchaseid END

but the query that I ran I am so slow and unresponsive so that it is not really a solution.

Does anyone have any other experience with these types of joining, where one column adds a mixture of 2 primary keys to different tables?

Am I clarifying something?

In situations where a join is very difficult to customize the query . Trying to type it in two different forms:

  WF c.customerID = wf.EntityID from the workflow left on the external client c and wf.ref = 1 external The engine = Wf.EntityID and wf.ref = 2  

left to join at P.purchaseID can work better to optimize these.


Comments