sqlite, join

复制代码
$sqlite3 t.db
.CREATE TABLE d (id INT PRIMARY KEY, name TEXT );
.INSERT INTO d VALUES(1, 'sales'), (2,'r&d'), (3, 'unknown');
.CREATE TABLE e (name TEXT, d_id INT REFERENCES d(id) );
.INSERT INTO e VALUES('tom', 1), ('jerry', 2), ('jone', 4), ('smith', NULL);
.SELECT * FROM e, d;
tom|1|1|sales
tom|1|2|r&d
tom|1|3|unknown
jerry|2|1|sales
jerry|2|2|r&d
jerry|2|3|unknown
jone|4|1|sales
jone|4|2|r&d
jone|4|3|unknown
smith||1|sales
smith||2|r&d
smith||3|unknown
.SELECT * FROM e INNER JOIN d ON id=d_id;
tom|1|1|sales
jerry|2|2|r&d
.SELECT * FROM e LEFT JOIN d ON id=d_id;
tom|1|1|sales
jerry|2|2|r&d
jone|4||
smith|||
.SELECT * FROM e RIGHT JOIN d ON id=d_id;
Error: RIGHT and FULL OUTER JOINs are not currently supported
.SELECT * FROM d LEFT JOIN e ON id=d_id;
1|sales|tom|1
2|r&d|jerry|2
3|unknown||
复制代码

SQLite Join - 菜鸟教程 | Join (SQL) - Detailed Pedia

But how? Three fundamental algorithms for performing a join operation exist: nested loop join, sort-merge join and hash join.

  1. A nested loop [嵌套循环] join is a naive algorithm that joins two sets by using two nested loops. 
  2. The key idea of the sort-merge [归并排序] algorithm is to first sort the relations by the join attribute, so that interleaved linear scans will encounter these sets at the same time.
  3. Hash joins require an equijoin predicate (a predicate comparing records from one table with those from the other table using a conjunction of equality operators '=' on one or more columns). [=前面这么多修饰!]
posted @   Fun_with_Words  阅读(22)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
历史上的今天:
2022-01-13 A Child's History of England.132
2022-01-13 ape
2022-01-13 apparatus
2022-01-13 app
2022-01-13 小白写给菜鸟看的消息队列简介
2022-01-13 apartment
2022-01-13 字节跳动笔试题-豆油瓶









 和5张牌。

点击右上角即可分享
微信分享提示