我只能查到一个。。。如下,我只能查到作者。。。不能同时查到接收者.. SELECT msg.*, users.name FROM message msg, users WHERE msg.ID = 1 and msg.author = users.ID
yangqi
2014-06-14 23:39:52 +08:00
SELECT m.ID, m.author, m.receiver, u1.author_name, u2.author_name as receiver_name FROM messages m LEFT JOIN users u1 ON u1.ID=m.author LEFT JOIN users u2 ON u2.ID=m.receiver
SELECT m.ID, m.content, m.author, m.receiver, u1.name as author_name, u2.name as receiver_name FROM messages m LEFT JOIN users u1 ON u1.ID = m.author LEFT JOIN users u2 ON u2.ID = m.receiver;
select n.id, n.content, n.author, n.receiver, n.name author_name, u2.name receiver_name from (select m.id, m.author, m.receiver, m.content, u1.name from messages m, user u1 where m.author = u1.id) n, user u2 where n.receiver = u2.id;