0

I have these tables :

enter image description here

enter image description here

enter image description here

enter image description here

I don't know how I can write a statement, that takes emails from Table "Firm", that have Location_id = '1' and Category_id = '130'; I know that I should use JOINs, but I'm not sure how to go from there.

2
  • you need to try something before posting questions, that's one of the easiest joins you might face in your life Commented Feb 17, 2014 at 15:28
  • I tryed something SELECT Firm.email FROM Firm INNER JOIN FirmID ON FirmID.location_id = '1' AND FirmID.category_id = '130'; Commented Feb 17, 2014 at 15:29

3 Answers 3

1
SELECT Firm.email 
FROM Firm 
INNER JOIN FirmID ON Firm.firma_id = FirmID.firma_id 
WHERE FirmID.location_id = '1' 
AND FirmID.Category_id = '130'
Sign up to request clarification or add additional context in comments.

Comments

0

Should be as simple as doing the following:

SELECT email
FROM Firm, FirmID
WHERE Firm.firma_id = FirmID.firma_id
AND FirmID.location_id = 1
AND FirmID.category_id = 130;

It does a join behind the scenes, but can be a bit clearer to understand than using the JOIN keyword.

4 Comments

I really wouldn't advise to use that syntax instead of the join one.
Could you explain why? My understanding was that it was no less efficient than explicitly using the JOIN keyword, as SQL still does a join. Thanks
Thanks for clarifying your point. However, I think the outcome of that particular question is that the two are synonyms - the advantages of either option (in a case as simple as this) are stylistic. I was just trying to help the OP understand what a join meant :-)
0

You could do:

SELECT f.email 
FROM Firm f 
WHERE f.firma_id = 
(
    SELECT ff.firma_id 
    FROM FirmID ff 
    WHERE ff.location_id = 1 
    AND ff.category_id = 130
)

Using an inner select.

But using JOINS is in the long term the way to go, what have you tried and what's not working?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.