Reputation: 91
I'm trying to compare the columns of a table and fetch the unmatched rows.Can someone help me to write a query to fetch the rows where Email_ID not in the format of [email protected] in the below scenario.
TABLE
S.no Firstname Lastname Email_ID
701 Sean Paul [email protected]
702 Mike Tyson [email protected]
703 Richard Bernard [email protected]
704 Simon Sharma [email protected]
Upvotes: 1
Views: 65
Reputation: 14077
SELECT *
FROM YourTable
WHERE CHARINDEX(FirstName + '.' + LastName + '@', Email) = 0
Upvotes: 1
Reputation: 44696
Search for rows where mail address not like Concat( firstname . lastname @)
select * from tablename
where Email_ID NOT LIKE (Firstname + '.' + Lastname + '@%')
Upvotes: 2
Reputation: 108975
You mean something like:
select -- some columns
from table
where Email_ID <> (FirstName + '.' + Lastname + '@abc.com')
?
There is nothing in SQL to prevent comparing one column with another, and – with a little more syntax – even across rows.
Upvotes: 3