SQL MySQL查询连接两个表

时间:2015-05-27 18:05:57

标签: mysql sql

我有以下结构。

表:联系

Id, Name, Email, PrimaryPhone, Description, CompanyId*

表:公司

Id*, Name, Email, Description

我想查询返回:

Contact.Name, Contact.Email, Contact.PrimaryPhone, Company.Name, Company.Email, Contact.Description. Company.Description, Contact.CompanyName

WHERE Contact.Name Like '%x%' or Company.Name LIKE '%x%'

2 个答案:

答案 0 :(得分:1)

SELECT 
    Contact.Name, Contact.Email, Contact.PrimaryPhone, Company.Name, 
    Company.Email, Contact.Description. Company.Description, Contact.CompanyName
FROM Contact
RIGHT JOIN Company ON Company.Id = Contact.CompanyId
WHERE Contact.Name LIKE '%x%' OR Company.Name LIKE '%x%'

答案 1 :(得分:0)

{{1}}