Lets say I have this table:
------------------------------------------------
| id | user_id | message | reply_to_message_id |
------------------------------------------------
| 1 | 1 | a | null |
| 2 | 1 | b | null |
| 3 | 1 | c | null |
| 4 | 1 | d | 1 |
| 5 | 2 | e | null |
------------------------------------------------
My purpose of the query is to get all the messages which message col matches search query as well as all the messages which have reply_to_message_id equal to id of the result of the previous part. I hope this make sense, my brain is junk by the end of the day.
The result with search query 'a' would be:
-----------------
| id | is_reply |
-----------------
| 1 | false |
| 4 | true |
-----------------
I have the first part:
SELECT id FROM messages
WHERE user_id = 1 AND message LIKE "%a%"
Of course I can loop through the result of this query but it's not right and I feel like there has to be an easy way to get this result.
BTW I'm using laravel query builder but I don't think that it has what I need.