I have a table which has two keys and I cannot break the table up into two.
The first key, id is a counter. The second key is parent_id.
For example:
id, parent_id, text
1, 0, Hello Steve - this is Bill
2, 1, Hi - how are you Bill?
3, 0, Good morning Janice
4, 3, Hello - good morning to you
The first record is the parent record of the conversation and the second is the child record.
What I'm having difficulty doing is writing a query that returns both records for a single conversation when you pass either id.
For example:
select * from table where id = 2 or parent_id = ( select parent_id from table where id = 2 )
select * from table where id = 1 or parent_id = ( select parent_id from table where id = 1 )
The first query will work, returning the records with id 1 and 2. The second will not as it will return the row with id 3 as well because if you pass 1 you'll get zero for the parent_id.
I'm sure it's something simple that I'm missing due to paralysis by analysis.
Thanks.