sql:表的加减法表的加法:union(并集)
lect product_id, product_name
from Product
union
lect product_id, product_name
from Product2;
取并集就是将两表中的数据结合在⼀起:
union等集合操作符通常都会去除重复的记录。
踩高跷
集合运算的注意事项:1.作为运算对象的记录的列数必须相同
2.作为运算对象的记录中列的类型必须⼀致
not your kind of people
reboot是什么意思3.可以使⽤任何lect语句,但order by⼦句只能在最后使⽤⼀次若想要在集合运算后结果包含重复⾏,需在union后添加all关键字。
选取表中公共部分:interct(交集)
lect product_id, product_name
from Product灵修培训
interct
lect product_id, product_name
胜利者英文from Product2
order by product_id;be ud to
取出两表中相同的项:
记录的减法:except(差集)personal interests
地狱英文lect product_id, product_name
from Product
except
lect product_id, product_name
洋洋得意是什么意思
英语六级报名官网入口from Product2
order by product_id;
所有属于A表且不属于B表的元素构成的查询结果(仅属于A表的值):这⾥被减数和减数交换位置,结果是不相同的:变成仅属于B表中的值:
lect product_id, product_name
from Product2
except
lect product_id, product_name
from Product
order by product_id;