Interview Question
Country: United States
Consider a table persons2 with First Name and Last Name being the columns that are
being checked against each other and with an ID column for each row (it could be whatever unique key you would like)
--You can achieve the results you need using the Scalar Subquery below
select count(*) as totaRows, (select COUNT(*)
from persons2 b,
persons2 c
where c.id = b.id
and c.first_name = b.last_name
) as matchingCount,
(select COUNT(*)
from persons2 b,
persons2 c
where c.id = b.id
and c.first_name <> b.last_name
) as nonMatchingCount
from persons2 a
if the table is twocols with columns one and two the following query works:
- kasterma January 04, 2012