I want to show a relation between two persons in a datagridview (C# Windowsforms).
So, I made a (MS Access) table with persons. Each person has an unique number as its PK. Thereafter I made a Relation table. In this table I have a column for person 1 (FK), a column for the relation and a column for person 2 (FK).
This looks like this:
Now I tried to show this in a datagridview with columns that show Fname
, Lname
, DOB
, Relation
, Fname
, Lname
, DOB
. I tried a lot, but I can't let it work.
I hope someone can let me know how the (SQL) select
query should look like or what I should do to make this work.
Thanks a lot!
You will need to use two references of your Person
table in your query, since, for each record in your Relation
table, two separate records are to be displayed from your Person
table.
Therefore, you'll need to use a query along the lines of:
select
p1.fname,
p1.lname,
p1.dob,
r.relation,
p2.fname,
p2.lname,
p2.dob
from
(relation r inner join person p1 on r.pnumber1 = p1.pnumber)
inner join
person p2 on r.pnumber2 = p2.pnumber
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments