Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张朋友桌。是否可以对表的两个字段进行左连接。换句话说,我不知道这两个字段中的哪一个可能有我需要的匹配项。如果没有,还有其他方法可以做到这一点吗?
$sql = "SELECT * FROM `friends` f LEFT JOIN `users` u ON f.askee OR f.asker = u.ID where (asker='$userid' OR askee='$userid') AND status='3'";
左连接是正确的:OR 运算符会按照您的预期进行。但是你的过滤器$userid应该应用于父表(friends),而不是左连接一个(否则它会取消外连接):
$userid
friends
$sql = "SELECT * FROM `friends` f LEFT JOIN `users` u ON f.`askee` = u.`ID` OR f.`asker` = u.`ID` WHERE u.`status` = '3' AND u.ID = '$userid'";