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 Firstname.Lastname@abc.com in the below scenario.
TABLE
S.no Firstname Lastname Email_ID 701 Sean Paul Sean.Paul@abc.com 702 Mike Tyson Mike.Samuel@abc.com 703 Richard Bernard Jim.Anderson@abc.com 704 Simon Sharma Rita.sharma@abc.com
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.
Search for rows where mail address not like Concat( firstname . lastname @)
select * from tablename
where Email_ID NOT LIKE (Firstname + '.' + Lastname + '@%')
SELECT *
FROM YourTable
WHERE CHARINDEX(FirstName + '.' + LastName + '@', Email) = 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.