[英]mysql :How to select two different column values from a single table using two different values of another table
[英]How can I select two different values from another table using only a single query?
要獲取用戶名和用戶select id, name from user u, message m where u.id=m.from_ID and u.id=m.to_ID
嘗試這個:
SELECT m.id 'message_id',
`u1`.`name` `from_name`,
`u2`.`name` `to_name`
FROM `message` `m`
JOIN `user` `u1` ON `m`.`from_id` = `u1`.`id`
JOIN `user` `u2` ON `m`.`to_id` = `u2`.`id`
SELECT from.name as FromUser, to.name AS ToUser
FROM user AS from, user AS to, (SELECT * FROM message where id=somevalue) AS m
WHERE from.emp_id = m.from_id AND to.emp_id=m.to_id;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.