从多个表自动完成
我想知道从多个表获取自动完成结果的最有效方法是什么?
需要注意的是;我希望能够识别记录来自哪个表。
例如,给定这些示例表:
+- People
+- id
+- name
+- age
+- Places
+- id
+- name
+- distance
+- Things
+- id
+- name
+- color
虽然包含一些与此问题相关的任意数据,但这里的主要焦点是 name
列(尽管这些可能是其他内容,或者每个正在查询的表有多个)
无论如何,我我正在尝试弄清楚如何通过自动完成功能查询每个表中的数据,并返回数据以及它所在的表。例如,字母 A
的输出可能如下所示:
Apple (Things)
Amy (People)
Aaron (People)
Anaheim (Places)
Axe (Things)
这最好通过单个查询还是跨各个表的多个查询来完成?
提前致谢 :)
I'm wondering what is the most efficient way to obtain autocomplete results from multiple tables?
The caveat being; I want to be able to identify from what table the records are coming.
For example, given these example tables:
+- People
+- id
+- name
+- age
+- Places
+- id
+- name
+- distance
+- Things
+- id
+- name
+- color
While containing some data arbitrary to this issue, the main focus here is the name
columns (though these could be something else, or multiple per table being queried)
Anyways, I'm trying to figure out how to query each of these tables for data a' la autocomplete, and return the data and from what table it is. For example, the output for the letter A
may look something like this:
Apple (Things)
Amy (People)
Aaron (People)
Anaheim (Places)
Axe (Things)
Would this be best accomplished with a single query, or multiple queries across the various tables?
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在单个查询中使用 at union 来完成此操作:
现在您将获得匹配的名称和源表,并且您可以为自动完成下拉列表很好地格式化它。
You could do it with at union, in a single query:
Now you would get both the matching
name
and the source table, and you could format that nicely for your auto-complete drop down thingie.