在mysql服务器中的三个表中搜索数据[重复]

时间:2021-01-03 17:00:43

This question already has an answer here:

这个问题在这里已有答案:

Our requirement is making to search by name in three table which are

我们的要求是在三个表中按名称搜索

  1. product_phone
  2. product_tablet
  3. Product_accessories

First table containing columns(Id,model_name)

第一个包含列的表(Id,model_name)

Second table containing columns(Id,model_name)

包含列的第二个表(Id,model_name)

Third table containing columns(Id,model_name).

第三个表包含列(Id,model_name)。

So my requirement is to search by magnified glass by model_name these three table without using join. I don't have any combination of each table.

所以我的要求是通过model_name放大玻璃搜索这三个表而不使用join。我没有每张桌子的任何组合。

1 个解决方案

#1


to be able to run a select query across multiple tables you just build a query that references all the tables .

为了能够跨多个表运行选择查询,您只需构建一个引用所有表的查询。

select product_phone.name, product_tablet.name, product_accessories.name from product_phone, product_tablet, product_accessories

Be careful that your tables are not to big as to overwhelm your code with data , its a good idea to add a LIMIT clause to the end of your query to give you the specific number of results.

请注意,您的表格不会太大,以至于使用数据压倒代码,最好在查询末尾添加LIMIT子句,以便为您提供特定数量的结果。

LIMIT clauses - http://www.w3schools.com/sql/sql_top.asp

LIMIT条款 - http://www.w3schools.com/sql/sql_top.asp

As your id fields appear to be unrelated you should not attempt to use a join. If all the id's are unique then you could use a join , there a several different types of join but be careful with them as they can generate a lot of work for your database server.

由于您的ID字段似乎不相关,因此您不应尝试使用连接。如果所有id都是唯一的,那么你可以使用一个连接,有几种不同类型的连接,但要小心它们,因为它们可以为你的数据库服务器生成大量的工作。

joins - http://www.w3schools.com/sql/sql_join.asp

加入 - http://www.w3schools.com/sql/sql_join.asp

#1


to be able to run a select query across multiple tables you just build a query that references all the tables .

为了能够跨多个表运行选择查询,您只需构建一个引用所有表的查询。

select product_phone.name, product_tablet.name, product_accessories.name from product_phone, product_tablet, product_accessories

Be careful that your tables are not to big as to overwhelm your code with data , its a good idea to add a LIMIT clause to the end of your query to give you the specific number of results.

请注意,您的表格不会太大,以至于使用数据压倒代码,最好在查询末尾添加LIMIT子句,以便为您提供特定数量的结果。

LIMIT clauses - http://www.w3schools.com/sql/sql_top.asp

LIMIT条款 - http://www.w3schools.com/sql/sql_top.asp

As your id fields appear to be unrelated you should not attempt to use a join. If all the id's are unique then you could use a join , there a several different types of join but be careful with them as they can generate a lot of work for your database server.

由于您的ID字段似乎不相关,因此您不应尝试使用连接。如果所有id都是唯一的,那么你可以使用一个连接,有几种不同类型的连接,但要小心它们,因为它们可以为你的数据库服务器生成大量的工作。

joins - http://www.w3schools.com/sql/sql_join.asp

加入 - http://www.w3schools.com/sql/sql_join.asp