-1

My companies table contains detail data such as company name.

My sites table maps to the companies table in the company_sites table because companies can have multiple sites.

For example, Jim Co (id: 1000) has jim.com (id: 2000).

These are mapped as company_sites:id = 1; company_id: 1000; site_id: 2000.

How can I select all fields for Jim Co from companies where site_id = 2000?

I'm getting an alias error for companies when I try this.

Here's what I have so far:

SELECT * 
FROM companies 
INNER JOIN companies ON companies.id = company_sites.company_id
WHERE company_sites.site_id = 2000
4

2 回答 2

1

我想你打算加入这个company_sites表。

尝试这个:

SELECT * 
FROM companies 
INNER JOIN companies_sites ON companies.id = company_sites.company_id
WHERE company_sites.site_id = 2000
于 2013-07-16T00:01:47.613 回答
0

尝试:

SELECT * FROM companies c, company_sites s WHERE c.id = s.company_id && c.id = 2000;
于 2013-07-15T23:57:14.540 回答