Skip to content
Advertisement

Find an entry in sql dependent on other entries in the table

How can I return all entries in a table that contain a string in a given column if the same string is also present in the same column with a given suffix ?

So for example, given the suffix ‘bar’, and the following table:

id A
1 foo1
2 foo2
3 foo1bar

I want to return the the first entry, because there’s another entry (the third one) which has the same value when the suffix is appended.

Advertisement

Answer

SELECT t1.*
FROM table t1
JOIN table t2 ON CONCAT(t1.column, 'bar') = t2.column
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement