0

Hello,

I have 2 datatable, first table for customers personal information and second table for customers areas of interest. this two tables have same ID for same customers.

So, when i want to check my some group of customers(like who intrests on sports stuffs) i need filter my first table according to my second table.

is there any easy way to do it?

thanks for your helps :)

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Oneryavuz
1

yes you can join then or use nested select statements ,like this

Customers

custid
custname

Interest

interestid
custid
interestname

now you have to get all the customers who have interest in football , you can do like this .

select c.custid,c.custname ,i.interestname
from customers c
inner join interest i on i.custid = c.custid
where i.interestname = 'football'

and you can do like this also but this is not i recommend for you.

select c.custid,c.custname ,
            (select i.interestname from interest i where i.custid = c.custid and
             i.interestname = 'football') as InterestName
from customers c

the above query is faster then this.
tip: always try to avoid nested select statements in your query as much as possible. nested select statement slowdown your query.

Regards

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.