今天在开发的时候遇到了一个需求就是三遍关联查询,表A包含有表B和表C的uid,然后使用left join左关联查询:
SELECT c.`uid`, `fromuseruid`, `touseruid`, `refuid`, `refname`, `type`, `tousertype`, `desc`, `file`, `result`, `status` ,e.`uid`,e.`showname`,u.`uid`,u.`showname`
FROM
(complaint AS c LEFT JOINguserdb2.`userinfo`
AS u ON c.`fromuseruid` = u.`uid`)
LEFT JOIN guserdb2.`userinfo`
AS e ON c.`touseruid` = e.`uid`
WHERE
u.`showname` LIKE '%国%'
OR
e.`showname` LIKE '%国%'
这是一个三表关联的模糊查询