"select l.eteamid,l.userid,l.nickname,l.signature,l.skyuser,l.skypasswd,p.mobile,p.telephone from %s.entermember l left join\
%s.userinfo p on l.userid=p.userid \
where l.userid in (select k.userid from %s.entermember k where k.eteamid in (select id from %s.enterteam t \
where t.cid=(select t.cid from %s.enterteam t where t.id =(select e.eteamid from %s.userauth u left join %s.entermember e on e.id=u.id left join \
%s.enterteam t on e.id=t.id where u.userid='%s'))))",g_db_name.c_str (),g_db_name.c_str (),g_db_name.c_str (),g_db_name.c_str(), g_db_name.c_str(),g_db_name.c_str(),g_db_name.c_str(),g_db_name.c_str(),user_id);
请高人帮忙解释一下这个语句的意思,另外能否解释一下left join的意思
拜谢!!!
%s.userinfo p on l.userid=p.userid \
where l.userid in (select k.userid from %s.entermember k where k.eteamid in (select id from %s.enterteam t \
where t.cid=(select t.cid from %s.enterteam t where t.id =(select e.eteamid from %s.userauth u left join %s.entermember e on e.id=u.id left join \
%s.enterteam t on e.id=t.id where u.userid='%s'))))",g_db_name.c_str (),g_db_name.c_str (),g_db_name.c_str (),g_db_name.c_str(), g_db_name.c_str(),g_db_name.c_str(),g_db_name.c_str(),g_db_name.c_str(),user_id);
请高人帮忙解释一下这个语句的意思,另外能否解释一下left join的意思
拜谢!!!
是SQL语言中的查询类型,即连接查询。它的全称为左外连接(left outer join),是外连接的一种。
用法:
连接通常可以在select语句的from子句或where子句中建立,其语法格式为: from join_table join_type join_table [on (join_condition)] 其中join_table指出参与连接操作的表名,连接可以对同一个表操作,也可以对多表操作。对同一个表操作的连接称为自连接。 on (join_condition)用来指连接条件,它由被连接表中的列和比较运算符、逻辑运算符等构成。
举例说明:
例1:select bookinfo.bookname , authorinfo.hometown from bookinfo left join authorinfo on bookinfo.authorname=authorinfo.authorname; 例2: 表A记录如下: aID aNum 1 a20050111 2 a20050112 3 a20050113 4 a20050114 5 a20050115 表B记录如下: bID bName 1 2006032401 2 2006032402 3 2006032403 4 2006032404 8 2006032408 语句:select * from A left join B on A.aID = B.bID; 结果如下: aID aNum bID bName 1 a20050111 1 2006032401 2 a20050112 2 2006032402 3 a20050113 3 2006032403 4 a20050114 4 2006032404 5 a20050115 NULL NULL (所影响的行数为 5 行) 结果说明: left join是以A表的记录为基础的,A可以看成左表,B可以看成右表,left join是以左表为准的。换句话说,左表(A)的记录将会全部表示出来,而右表(B)只会显示符合搜索条件的记录(例子中为: A.aID = B.bID)。B表记录不足的地方均为NULL。
这个建议在 GOOGLE中搜索 LEFT JON 或者 左外连接, 然后找一篇比较容易看懂的先了解一下。在 《数据库系统概论(第四版)》 王珊 萨师煊 高等教育出版社 (掌握基础知识和概念) 这本书中,花了近1000字和图文 来解释这个外连接。