Sam Keith
Sam Keith

Reputation: 99

Query to match columns from two table with same area code for telephone number

I'm trying to write a query to find matches from two tables having the same area code for telephone number. e.g

Employee(name, telephone#)
Customer(name, telephone#)

Need to find name of employees with the same telephone area code(xxx-yyy-zzzz) as that of customer(xxx-yyy-zzzz). I can't specify the area code myself. Query should evaluate that. Maybe something like "LIKE" can be used?

Upvotes: 0

Views: 275

Answers (1)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

Use substr and join on the first 3 characters of the telephone column.

select e.name
from employee e 
inner join customer c on substr(e.telephone, 1, 3) = substr(c.telephone, 1, 3)

Upvotes: 3

Related Questions