You shouldn't store that information in one table, but in two tables, like
people
Code:
id | name | blood_type
------------------------
1 | John | B
2 | Kennth | A
children
Code:
id | parent_id | name
---------------------
1 | 1 | Mary
1 | 1 | Keith
1 | 1 | Alex
1 | 2 | Oliver
1 | 2 | Lich
And then to query
Code sql:
SELECT
p.name
FROM
people AS p
INNER
JOIN children AS c
ON
p.id = c.parent_id
WHERE
c.name = 'Alex'
OR you could put it all in one table and join that table on itself
people
Code:
id | parent_id | name | blood_type
-------------------------------------
1 | (NULL) | John | B
2 | (NULL) | Kenneth | A
1 | 1 | Mary | (NULL)
1 | 1 | Keith | (NULL)
1 | 1 | Alex | (NULL)
1 | 2 | Oliver | (NULL)
1 | 2 | Lich | (NULL)
Code sql:
SELECT
parent.name
FROM
people AS parent
INNER
JOIN people AS child
ON
parent.id = child.parent_id
WHERE
child.name = 'Alex'
The way you're storing the data now doesn't scale and will give you more problems than benefits.
Bookmarks