Assuming I have a table Table1
table in a MySQL database. The table has a single column called string
. Here is an example:
**Table1**
mytext
my-text
some-text
no-text
notext
yes-dash
yesdash
no-dash
I want to get rows of string
, from Table1
that match a REGEXP that matches only alpha characters and a single dash (-
).
I managed to get that with
SELECT * FROM Table1 WHERE string REGEXP '^[A-Za-z]+[-]{1}[A-Za-z]+$'
From the above example dataset, I will get back
some-text
my-text
no-text
yes-dash
no-dash
Now, what I really want to get is any string
from the result of the first query, that if the dash -
is removed, that new string does NOT exist in Table
.
From the example dataset, the following should be the output,
some-text
no-text
no-dash
Any ideas?