SQL三表左关联查询

今天在开发的时候遇到了一个需求就是三遍关联查询,表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 '%国%'

这是一个三表关联的模糊查询

SQL三表左关联查询_第1张图片

转载于:https://www.cnblogs.com/pig66/p/10421026.html

你可能感兴趣的:(SQL三表左关联查询)