-1

I have 2 tables, 1st table has domains and ID for the domain, 2nd table has customer info corresponding to that ID.

Using the domain name, I need to get the customer info for that domain, this can only be done by first getting the ID and using that ID to get the customer info.

I am able to successfully get the customer info from domain name, but the problem is, my final result must have the customer info and the domain name associated with it (2nd table has no domain name).

How I get the Customer Info:

SELECT ContactName, EmailAddress
FROM [Database].[dbo].[Customers]
WHERE CustomerID IN (
    SELECT CustomerID
    FROM [Database].[dbo].[Domains]
    WHERE DomainName IN (*list of domains*)
    )

So the final result must have a table with columns like this

ContactName | EmailAddress | DomainName

How would I go about this?

0

3 Answers 3

0

Just use a JOIN to do this if you have CustomerID in both tables:

SELECT c.ContactName, c.EmailAddress, d.DomainName 
FROM [Database].[dbo].[Customers] c
INNER JOIN [Database].[dbo].[Domains] d on d.CustomerID = c.CustomerID
WHERE DomainName IN (*list of domains*)
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT c.ContactName, c.EmailAddress,d.DomainName
FROM [Database].[dbo].[Customers] c,
join [Database].[dbo].[Domains] d
on c.CustomerID = d.CustomerID
WHERE d.DomainName IN (*list of domains*)

1 Comment

While this post may answer the question, it is still a good idea to add some explanation and, possibly, some links to the relevant documentation. Answers with good explanations and references are usually more useful both to the current OP and to the future visitors. Full detailed answers are also more likely to attract positive votes.
0

You need a JOIN between the two tables, something like

SELECT 
    c.ContactName, 
    c.EmailAddress, 
    d.DomainName
FROM 
    Customers c
    INNER JOIN
    Domains d
    ON 
    c.CustomerID = d.CustomerID
WHERE 
    d.DomainName IN ('Google', 'Yahoo');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.