Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:16:55+00:00 2026-06-09T07:16:55+00:00

Suppose I have some table in SQL Database with many data and some of

  • 0

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

  1. account is rejected:
  2. 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:16:56+00:00Added an answer on June 9, 2026 at 7:16 am

    The following removes everything from the first < onwards.

    The GROUP BY is more flexible than using DISTINCT but accomplishes the same thing in this case.

    The CASE statement is there to cater for the possibility of messages that do not have a < in them. If there is always a < Then just use the ELSE section instead.

    SELECT
      CASE WHEN CHARINDEX('<', Message) = 0 THEN Message ELSE LEFT(Message, CHARINDEX('<', Message)-1)) END AS Message
    FROM
      yourTable
    GROUP BY
      CASE WHEN CHARINDEX('<', Message) = 0 THEN Message ELSE LEFT(Message, CHARINDEX('<', Message)-1)) END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this database table (some sample code below) that stores the relationship
Suppose I have wrote script Table_ABC.sql which creates table ABC. I have created many
Suppose a database table containing properties of some elements: Table Element (let's say 1
Suppose that I have a database table that contains information on cities across the
Suppose I have a SQL table called AT_Devices with each record representing a piece
I have one query in SQL Server output, Suppose i have one table (Ex.StudentMaster)
Let's suppose I have a table in my database with 1.000.000 records. If I
I have couple of rows in database table (lets call it Customer), each row
Suppose I have an SQL Server 2005 table, TableX, with 2 indexes on it:
I have a simple application which stores the data into the sql server database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.