我需要从这个 MySql 语句返回的这些结果中获取表 sellers
和所有其他列(不知道列名)的 ID 和时间戳:
SELECT * FROM sellers a
LEFT JOIN users b ON a.user_id = b.id
LEFT JOIN country_types c ON a.country_type_id = c.id
LEFT JOIN language_types d ON a.language_type_id = d.id
WHERE a.email=?
虽然卖家 ID 设置不正确,因为用户、国家/地区类型和语言类型都有一个值 id
。如何设置 seller_id 和 seller_timestamp?我试过了,但它不正确:
SELECT a.id seller_id, a.timestamp seller_timestamp, * FROM sellers a ...
最佳答案
你想要这个:
SELECT a.id as seller_id, a.timestamp as seller_timestamp, a.*, b.*, c.*, d.*
FROM sellers a
LEFT JOIN users b ON a.user_id = b.id
LEFT JOIN country_types c ON a.country_type_id = c.id
LEFT JOIN language_types d ON a.language_type_id = d.id
WHERE a.email=?
关于mysql - MySQL 语句中的 LEFT JOIN 返回的 ID 不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21220089/