今天在開發的時候遇到了一個需求就是三遍關聯查詢,表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 '%國%'
這是一個三表關聯的模糊查詢