Suppose I have some table in SQL Database with many data and some of the rows are almost identical, for example:
|===========================================|
| Message |
|===========================================|
| ... |
|-------------------------------------------|
| account is rejected: <aa> |
|-------------------------------------------|
| account is rejected: <bb> |
|-------------------------------------------|
| mailbox unavailable: 550 550 <1@b.com> |
|-------------------------------------------|
| mailbox unavailable: 550 550 <2@b.com> |
|-------------------------------------------|
| ... |
for my purposes 2 first lines are identical and 2 last lines are identical, so the query should return
- account is rejected:
- mailbox unavailable: 550 550
I thought to write query that will select rows, eliminate chars after ‘<‘ sign and the will do DISTINCT, but I don’t know how to do all it in SELECT
Can you help me to write such query?
The following removes everything from the first
<onwards.The
GROUP BYis more flexible than usingDISTINCTbut accomplishes the same thing in this case.The
CASEstatement is there to cater for the possibility of messages that do not have a<in them. If there is always a<Then just use theELSEsection instead.