This topic has been archived. It cannot be replied.
-
工作学习 / 专业知识杂谈 / Ask a SQL query question (prefer in mysql . )2 tables:
Table1 has 3 columns: ename deptname place;
table2 has 2 columns: deptname place.
If table1's place is null, the people "ename" suppose working in the place defined in table2, other he/she work in the place defined in table1. Need a query to find out all people (ename) and their working places.
-tiantianma(Tiantianma);
2007-6-20
{314}
(#3753343@0)
-
大虾伸手吧.SELECT IFNULL(t1.place,t2.place) FROM Table1 t1 LEFT JOIN Table2 t2 ON t1.deptname=t2.deptname. Look for manual to make sure IFNULL or NULLIF. When tiantian sleeping, google "MySQL manual". next time, you know where you find answer quicker
-elecskunk(elecskunk);
2007-6-20
(#3754694@0)
-
是 nullif.
-whygh(studing);
2007-6-20
(#3755113@0)
-
Thanks.
-tiantianma(Tiantianma);
2007-6-20
(#3755528@0)