I have two tables, people and comment.
Table: people
+-------------------+----------------+-------------+------+
| id | cn | en | dob | role |
+-------------------+----------------+-------------+------+
| 1 | ChineseName | EnglishName | 1989-03-02 | 0 |
+-------------------+----------------+-------------+------+
| 2 | ChineseName2 | EnglishName2 | 1923-06-12 | 1 |
+-------------------+----------------+-------------+------+
Table: comment
+----+--------+----------+-------------------+---------------------+
| id | owner | owner_id | creator_person_id | comment |
+----+--------+----------+-------------------+---------------------+
| 1 | PERSON | 2 | 1 | Some comments here |
+----+--------+----------+-------------------+---------------------+
| 2 | TRANSAC| 1 | 1 | Comments |
+----+--------+----------+-------------------+---------------------+
| 3 | PERSON | 1 | 1 | Comments here |
+----+--------+----------+-------------------+---------------------+
When I execute the query:
SELECT comments.comment,
creator_person.id AS creator_id,
creator_person.cn AS creator_cn,
creator_person.en AS creator_en,
creator_person.dob AS creator_dob,
creator_person.role AS creator_role
FROM people, comments
JOIN people AS creator_person
ON comments.creator_person_id = creator_person.id AND comments.owner = 'PERSON' AND comments.owner_id = 1
ORDER BY people.id
I suppose it will return me only 1 row, however I'm getting a duplicate of that row:
+------------------+------------+-------------+-------------+-------------+--------------+
| comment | creator_id | creator_cn | creator_en | creator_dob | creator_role |
+------------------+------------+-------------+-------------+-------------+--------------+
| Comments here | 1 | ChineseName | EnglishName | 1989-03-02 | 0 |
+------------------+------------+-------------+-------------+-------------+--------------+
| Comments here | 1 | ChineseName | EnglishName | 1989-03-02 | 0 |
+------------------+------------+-------------+-------------+-------------+--------------+