我在MySQL中有两个表,customer
和contacts
customer
中的每一行都可以对应多行contacts
,而且contacts.company
等于customer.sequence
我该如何运行查询来搜索这两个表并只返回customer
表中的结果?
例如,如果我有以下数据:
customer:
sequence = 123
company = Company A
sequence = 321
company = Company B
contacts:
company = 123
forename = John
company = 123
forename = Steve
company = 321
forename = Joe
company = 321
forename = Andy
company = 321
forename = John
如果我搜索Andy,它应该返回公司A
如果我搜索John,它应该返回公司A
和公司B