sqlite3 联表查询 代码

前端之家收集整理的这篇文章主要介绍了sqlite3 联表查询 代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. select USER.USERNAME,USER.USERNAMEP,USER.PHOTOURL,USER.ADMIN,USEREX.RELATION,USEREX.SUBRELATION,USEREX.LASTTIME,_MESSAGE.CONTENT,_MESSAGE.SENDTYPE,_MESSAGE.DIRECTION \ from USER,USEREX left join (select CONTENT,max(TIMetaG) as MAXTIMetaG,DIRECTION,SENDTYPE from MESSAGE where MYID = ? and USERID = ? and GROUPID = 0)_MESSAGE \where USER.USERID = ? and USEREX.USERID = USER.USERID and USEREX.MYID = ? and USEREX.LASTTIME > 0;
  2. (select xxx from xxx left join(select xxx from xxx where xxx) xxx where xxx);

  1. select MESSAGE.USERID,MESSAGE.DIRECTION,MESSAGE.CONTENT,MESSAGE.TIMetaG,MESSAGE.MYID,MESSAGE.SENDTYPE,MESSAGE.TIMESPAN,MESSAGE.UNREADFLAG,USER.USERNAME \from MESSAGE left join USER on MESSAGE.USERID = USER.USERID \where MESSAGE.USERID >= 0 and MESSAGE.MYID = ? and MESSAGE.GROUPID = ? order by MESSAGE.TIMetaG desc limit ?;
  2. (select xxx from xxx left join xxx on xxx where xxx);

select USER.USERID,USER.USERNAME,_MESSAGE.MAXTIMetaG,_MESSAGE.DIRECTION,MESSAGECOUNT.COUNT,USER.SEX \ from USER,USEREX \ left join (select USERID,max(TIMetaG) as MAXTIMetaG,CONTENT,SENDTYPE from MESSAGE where MYID = ? and GROUPID = 0 group by USERID) _MESSAGE on USEREX.USERID = _MESSAGE.USERID \ left join MESSAGECOUNT on MESSAGECOUNT.ID = USEREX.USERID and MESSAGECOUNT.TYPE = 0 and MESSAGECOUNT.MYID = ? \ where USEREX.LASTTIME > 0 and USEREX.MYID = ? and USER.USERID = USEREX.USERID;

(select xxx from xxx left join (select xxx as xxx from xxx where xxx group by xxx) on xxx left join xxx on xxx where xxx)



select GROUPS.GROUPID,GROUPS.GROUPNAME,GROUPS.GROUPNAMEP,GROUPS.PICTUREURL,GROUPEX.LASTTIME,MESSAGECOUNT.COUNT from GROUPS,GROUPEX \

left join (select MESSAGE.GROUPID,_MSGTMP.MAXTIMetaG,MESSAGE.USERID,MESSAGE.SENDTYPE from MESSAGE,(select max(TIMetaG) as MAXTIMetaG,GROUPID from MESSAGE where MYID = ? and USERID >= 0 and GROUPID > 0 group by GROUPID) _MSGTMP where MESSAGE.GROUPID = _MSGTMP.GROUPID and MESSAGE.TIMetaG = _MSGTMP.MAXTIMetaG and MESSAGE.MYID = ?) _MESSAGE on GROUPEX.GROUPID = _MESSAGE.GROUPID \

left join USER on USER.USERID = _MESSAGE.USERID \

left join MESSAGECOUNT on MESSAGECOUNT.MYID = ? and MESSAGECOUNT.ID = GROUPEX.GROUPID and MESSAGECOUNT.TYPE = 1 \

where GROUPEX.MYID = ? and GROUPEX.GROUPID > 0 and GROUPEX.LASTTIME > 0 and GROUPS.GROUPID = GROUPEX.GROUPID;


(select xxx from xxx left join (select xxx from (select xxx from xxx where xxx group by xx) where xxx )on xxx left join xxx on xxx let join xxx on xxx where xxx)

备注:“\” ,代表行末换行的意思

猜你在找的Sqlite相关文章