trembling trembling - 2 years ago 85
SQL Question

join elements from three unrelated tables

SQL newbie here. I have the following schema.

I am to provide a list of all active primary super charged domains belonging to the foobar association.

As far as I know, three tables (sites, domain, and name) cannot be joined together. How can this be done?

Answer Source

This is an example of joining three tables

SELECT * FROM companies
JOIN sites ON =
JOIN domains ON =
    sites.is_supercharged = 1 AND sites.is_deleted = 0 AND 
    domains.is_primary = 1 AND domains.is_deleted = 0

It based on the schema (I hope the field names are correct, the text is quite small)

When you joining a table to a query, you need to specify the matching fields reference in the ON part. And then you can add any condition in the WHERE part.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download