select *from haha where exists (select *from bumen where bumen.code = haha.bumen and bumen.name = '銷售部' )and age>35安全
(運行方法爲逐條查詢)code
select name,sex,age,(select name from bumen where bumen.code = haha.bumen)as 部門 from haha排序
select name,sex,age,(select name from bumen where bumen.code = haha.bumen)as 部門,(select ceo from bumen where bumen.code = haha.bumen)as ceo from hahaio
1.select
select haha.name,sex,age,bumen.name,ceo from bumen,haha where haha.bumen = bumen.code數據類型
2.join on(順序可顛倒)nio
select haha.name,sex,age,bumen.name,ceo from haha方法
join bumen on haha.bumen = bumen.code數據
3.full的用法查詢
insert into haha values(15,'實物','nv',34,5)
insert into bumen values(6,'保安部','保證安全',null,null)
select bumen.name,zhineng,ceo,haha.name,sex,age from haha
full join bumen on bumen.code = haha.bumen
4.left的用法
在沒有關係的狀況下,只顯示join左邊表的全部數據,不顯示右邊表的數據
5.right的用法
同上
(left 和right都是與所所有顯示的數據的排序方式一致)
將兩列鏈接起來,必須知足數據類型對應,具備自動去重的功能(按照拼音或者數字排列,打亂原有的順序)
select*from haha where code > 10
union
select*from haha where code < 5
select name,bumen from haha where code > 10
union
select ceo,code from bumen