I am currently in the process of developing a Database software for a company that I am working with. I based the tables off of Len Silverston's book, as I found it to be an excellent source for information based on data modeling.
Now, you do not need to be acquainted with his book to know the solution to my problem, but I could not think of any other way to word my title.
Suppose I have two tables, Persons and Person_Names:
CREATE TABLE Persons
(
party_id INT PRIMARY KEY,
birth_date DATE,
social VARCHAR(20)
);
CREATE TABLE Person_Names
(
party_id INT,
name_id INT,
person_name VARCHAR(20),
CONSTRAINT person_names_cpk
PRIMARY KEY (party_id, name_id)
);
The two tables can be joined by party_id. Also, under Person_Names, name_id = 1 correlates to the person's first name (which is stored in the field person_name) and name_id = 2 is the person's last name.
* EDIT *
Someone asked for some data, so I will add some data below:
INSERT INTO Persons VALUES
(1, '01-01-1981', '111-11-1111'),
(2, '02-02-1982', '222-22-2222'),
(3, '03-03-1983', '333-33-3333');
INSERT INTO Person_Names VALUES
(1, 1, 'Kobe'),
(1, 2, 'Bryant'),
(2, 1, 'LeBron'),
(2, 2, 'James'),
(3, 1, 'Kevin'),
(3, 2, 'Durant');
Now that I added those data, how would I query the following?
-----------------------------------------------------------------------
| Party Id | First Name | Last Name | Birthdate | Social No. |
-----------------------------------------------------------------------
| 1 | Kobe | Bryant | 01-01-1981 | 111-11-1111 |
| 2 | LeBron | James | 02-02-1982 | 222-22-2222 |
| 3 | Kevin | Durant | 03-03-1983 | 333-33-3333 |
-----------------------------------------------------------------------
Thanks for taking your time to read my question!