I have a table named CUSTOMER and it has columns FirstName, LastName, Phone, and
ID: 669045 • Letter: I
Question
I have a table named CUSTOMER and it has columns FirstName, LastName, Phone, and Email.
The question I have to perform is:
List only those customers who have the same name (First and Last). Use a subquery.
I can use a subquery to go through and find common first names. How do I add the last name to the subquery so that I can find an exact match of first and last? My code below finds first name matches. Thanks for the help...
SELECT FirstName
FROM CUSTOMER
WHERE FirstName in (SELECT FirstName FROM CUSTOMER GROUP BY FirstName HAVING COUNT(FirstName) > 1);
Explanation / Answer
SELECT a.* FROM CUSTOMERS a WHERE a.FirstName IN (SELECT b.FirstName FROM CUSTOMERS b WHERE (b.FirstName = a.FirstName and b.LastName = a.LastName ) GROUP BY b.FirstName having COUNT(b.FirstName ) > 1) order by a.FirstName;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.