【发布时间】:2020-09-12 02:36:32
【问题描述】:
假设我的数据库中有 3 个这样的表。
table A table B table C
id|title|body id|name |desc id|user |comment
1 |xx |xy 1 |zy |yz 1 |zz |yz
2 |xyz |yy 2 |xx |xx 2 |xx |xy
3 |zy |xx 3 |yy |yy 3 |yyy |yz
当搜索字符串是“x”时,结果应该是
|col1 |col2|
|xx |xx | -- from table B, because 4 occurrences
|xx |xy | -- from table A, because 3 occurrences
|xx |xy | -- from table C, because 3 occurrences
|zy |xx | -- from table A, because 2 occurrences
|xyz |yy | -- from table A, because 1 occurrence
我应该在 SQLite 中运行哪个查询来获得这样的结果?
编辑:更改 B 和 C 中的列名以显示它们不相关。
【问题讨论】:
-
如果这些标题和正文相关,它们应该在一个表中并被引用。
-
不是,我应该改一下更清楚。
标签: sql string sqlite sql-order-by union