I have a table
id|customer_id|comment
1 34 good
2 23 bad
3 34 regular
4 76 longterm
5 34 bad
6 23 good
We can see that one customer_id has different comment (ex – 34 has good regular bad)
I am trying to pull records from the above table where comment is “good and also bad” and group by customer_id so in the result I should see the records id => 1, 5, 2, 6
Can someone please help me in writing this where clause.
regards
To have one row of data reference another row, you need a join. In this case you’ll want to join comment against itself:
I’ve chosen the
a.id < b.idsyntax to avoid doing the same join in both directions, resulting in duplicate work. By specifying distinct, you’ll see each customer only once.