eapro
10-18-2009, 11:30 AM
Each time a new person is added, they will get their own id starting at 1, and each time their name is added, their id will increment by 1.
To add a new entry, I would have to first lock the whole table, then get the last id for that person, then do another query to insert with id + 1.
How can I achieve this without creating a separate table for each person? Any ideas?
NOTE: These example tables are ONLY to give you an idea of what I'm trying to achieve as simply as possible.
Showing all names
+--------------+-----------------------+
| id | name |
+--------------+-----------------------+
| 1 | Bob |
| 1 | Marry |
| 2 | Bob |
| 1 | John |
| 3 | Bob |
| 2 | Marry |
+--------------+-----------------------+
Showing only where name = Bob
+--------------+-----------------------+
| id | name |
+--------------+-----------------------+
| 1 | Bob |
| 2 | Bob |
| 3 | Bob |
+--------------+-----------------------+
To add a new entry, I would have to first lock the whole table, then get the last id for that person, then do another query to insert with id + 1.
How can I achieve this without creating a separate table for each person? Any ideas?
NOTE: These example tables are ONLY to give you an idea of what I'm trying to achieve as simply as possible.
Showing all names
+--------------+-----------------------+
| id | name |
+--------------+-----------------------+
| 1 | Bob |
| 1 | Marry |
| 2 | Bob |
| 1 | John |
| 3 | Bob |
| 2 | Marry |
+--------------+-----------------------+
Showing only where name = Bob
+--------------+-----------------------+
| id | name |
+--------------+-----------------------+
| 1 | Bob |
| 2 | Bob |
| 3 | Bob |
+--------------+-----------------------+