在一个查询中搜索多个表(MySQL / PHP#) [英] Search Multiple Tables at in one query (MySQL/PHP#)

查看:156
本文介绍了在一个查询中搜索多个表(MySQL / PHP#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约15个表,每个表包含大约10 000行和大约30列。我希望我的网站的用户能够搜索零件号,或产品/描述和显示结果。无论它在哪个表中。



每个产品页面与每个相应表的名称相同。因此,如果找到一个产品,它只会显示一个链接到正确的页面(文件名是表的名称)。



我们不能做某事like:



query =find $ q in dbase.tables; ?



如果$ q存在于表中,则返回在其中找到的表的名称。





谢谢

解决方案

这些表具有相同的结构,你可能能够做到。 (这听起来像是一个简单的手动分区方案。)



无法连接多个表格你可以使用

  SELECT * FROM tbl1 
UNION ALL
SELECT * FROM tbl2
...

为了得到你的简单访问方法,你可以创建一个视图的连接:

  CREATE VIEW alltables AS 
SELECT * ... UNION ...

不曾经测试过这个。但是这个视图会方便 SELECT * FROM alltables WHERE find($ q)... - 你仍然需要一个有效的查询列。 >

I have about 15 tables, each table containing about 10, 000 rows and about 30 columns. I want the users of my site to be able to search for a Part Number, or a product/description and display the results. Regardless of which table it's in.

Each product page is the same as the name of each corresponding table. So if a product is found, it will just display a link to the correct page (the filename is the name of the table).

Can't we just do something like:

query = "find $q in dbase.tables"; ?

And if $q exists in a table, return the name of the table it was found in?

Any help is appreciated!

Thank you

解决方案

If all the tables have the same structure you might be able to do that. (That sounds like it's a simplistic manual partitioning scheme.)

Anway to join multiple tables you can use

SELECT * FROM tbl1
UNION ALL
SELECT * FROM tbl2
...

And to get your simple access method you might create a view on that concatenation:

CREATE VIEW alltables AS
    SELECT * ... UNION ... 

Not ever tested this. But this view would then facilitate SELECT * FROM alltables WHERE find($q)... - you'd still need a valid query for the columns of course.

这篇关于在一个查询中搜索多个表(MySQL / PHP#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆