sql server - How to find rows in SQL that start with the same string (similar rows)? -


I have a table with such a primary key, which looks like this:

The first ABC FIRST KEY ~ DEF

I want to write a SELECT statement that closes the segment after the tilde Duplicate gives all the lines that section has gone, this is

SELECT ...

gives me:

First / ABC

The first DEF

of the first "duplicate".

I already have a little bit of touching the last segment using SUBSTRING:

SELECT SUBSTRING (COLUMN, 0, CHARINDEX ('~', COLUMN) from the table

This is on the SQL Server.

The first solution given will determine the key prefix To start the rows of the table with those keys, extend it a bit:

  Select from which to select the tablet (column, 0, fourteenx ('~', COLUMN)) ( Select SUBSTRING (column, 0, fourteenx ('~', COLU MN) from subtracting (column, 0, chordiex ('~', COLUMN) from table group to COUNT (*)> 1)  

Alternatively, And can be used to connect between a floating table with the original table - if the number of prefixes is too large, "where in" can be very expensive.


Comments