Using FK in two table of one table select query not retrieving correct result
i am taking Name from Register table.
I am taking group of patient from Patient table where Register table ID is foreign key.
Donor name is taking from Donor table and group (Dname).
i want that record which is in cross match table.
Sorry remove RID field from crossmatch table.
use PID from patient table and DID from field from donor table
Below is my data and outut
CREATE TABLE #Group(BID INT,BName VARCHAR(50))
CREATE TABLE #Register(RID INT,PName VARCHAR(50))
CREATE TABLE #Patient(PID INT,RID Int,BID int)
CREATE TABLE #Donor(DID INT,DName VARCHAR(50),BID int)
CREATE TABLE #CrossMatch(CID INT,RID int,DID int )
INSERT INTO #Group VALUES(1,'A')
INSERT INTO #Group VALUES(2,'B')
INSERT INTO #RegisterVALUES(101,'Akhter','1')
INSERT INTO #Patient VALUES(1,101,'1')
INSERT INTO #Donor VALUES(1,'Hussain','2')
INsert into #CrossMatch Values(1,101,1)
output From Cross Match table
Patient |
Group |
Donor |
Group |
Akhter |
A |
Hussain |
B |