I have a table and there are two columns.
user_id | to_user_id |
---|---|
101 | 102 |
102 | 101 |
101 | 105 |
In the above table, 1 and 2 rows of users are like each other I want to remove 2 rows.
Here is my code.
$query = AppModelsMyMatch::query();
$query->whereHas('users')->whereHas('tousers')
->select('my_matches.*')->distinct()
->where('user_id', '!=', 'to_user_id');
$records = $query->get();
In the above code, I got total 3 rows
I want only a total of 2 rows 1 and 3
So, how can I write a query for it
2
Answers
or use a subquery :
You can use