2014-04-17 69 views
0
employee 
id name 
1 mark 
2 Clark 
3 Johnson 
4 peter 


emp_salary 

empid sal 
1  2000 
2  4000 
2  null 
4  6000 
5  null 

我需要其薪水爲空員工姓名...也是我需要顯示5000,其中工資薪金爲空,在不emp_salary表中插入值如何創建虛擬表在MySQL中插入空值

我試圖

Select e.name,e.empid,e.salary 
from table employee e inner join emp_salary em on e.id=em.empid 
where em.salary=null 

但此查詢不工作

,我需要選擇空值和空值顯示5000,而不會影響表

+0

只需使用值'null'作爲默認值 – WASasquatch

回答

1
Select e.name,e.empid,'5000' salary 
from table employee e inner join emp_salary em on e.id=em.empid 
where em.salary is null 

檢查與空「IS NULL」而不是「= NULL」

這將顯示其薪水爲空所有的員工,但你的選擇將顯示「工資」爲5000