【发布时间】:2013-09-05 08:58:35
【问题描述】:
我有两个名为 company 和 customers 的表。
在company 表中有3 个字段ID、Company 和Type:
ID Company Type
1 ABC Running
2 XYZ Current
现在再次在customers 表中我提交了公司和客户的价值,但这里公司的价值作为ID 提交为:
Company Customer Name
1 monty
2 sandeep
现在我想在客户表中搜索公司名称,但是当我将公司名称放在搜索框中时,它什么也没显示,因为公司名称的值是客户表中的 ID 形式。我该如何实现它。
这是我的搜索查询:
$sql = "Select * from customers where name like '%$term%' or location like '%$term%' or company like '%$term%'";
【问题讨论】:
-
Monty,你应该看看 JOINS in SQL。它们非常重要,您肯定会一直使用它们。您可以通过此链接开始使用w3schools.com/sql/sql_join.asp
-
@medina: 非常感谢这个宝贵的建议。
标签: mysql select where sql-like