N2012
asked on
SQL Query of records with two equal columns
I can't seem to be able to create/find a query that shows results (all records) that have the same First and Last Name (two separate fields).
And if you would like to display whole rows containing above names use the following query:
SELECT Y.*
FROM YourTable Y
JOIN (SELECT FirstName, LastName, COUNT(*) cnt
FROM YourTable
GROUP BY FirstName, LastName
HAVING COUNT(*) > 1) D
ON D.FirstName = Y.FirstName AND D.LastName = Y.LastName
ORDER BY Y.FirstName, Y.LastName
ASKER
pcelba - thanks, but that gives me a count. I don't want a count if there are multiple records. I don't care about multiple records, but rather records that have two identical fields (firstname and lastname).
In other words, I want to show the records - and only those records - that have the FirstName identical to the LastName.
In other words, I want to show the records - and only those records - that have the FirstName identical to the LastName.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
That's what I thought I tried before and got an error.
Works. :)
Works. :)
Open in new window