我刚使用此代码,并与我合作:
SELECT
* FROM `order` as o
LEFT JOIN `services` as s ON s.`id` = o.`service_id`
LEFT JOIN `users` as u ON u.`id` = o.`users_id`
LEFT JOIN `files` as f ON f.`order_id` = o.`id`
但是当我尝试从第一个表中选择一些字段时,结果没有显示其他表
SELECT
o.`id` AS `id`,
o.`service_id`,
o.`extras`,
o.`quantity`,
o.`price`,
o.`links`,
o.`keywords`,
o.`status_id`,
o.`users_id`,
o.`date`,
o.`notes`,
o.`c_reason`,
o.`agent_star`
FROM `order` as o
LEFT JOIN `services` as s ON s.`id` = o.`service_id`
LEFT JOIN `users` as u ON u.`id` = o.`users_id`
LEFT JOIN `files` as f ON f.`order_id` = o.`id`
我不知道第二个代码的确切错误是什么,我需要显示表中的所有列:services,users&档 所有列或刚定义的列
答案 0 :(得分:0)
当您从联接中选择*时,您正在从所有相关表中选择所有结果。
当您指定订单时,您只获得与订单表相关的结果,如果您要执行SELECT o。*,那么如果您想要查看来自不同表的共享字段,则必须指定它们也在你的select语句中。
基本上你看到了SELECT *和SELECT o。*
之间的区别答案 1 :(得分:0)
这段代码对我有用,谢谢大家:)
SELECT
o.`id` AS `id`,
o.`service_id`,
o.`extras`,
o.`quantity`,
o.`price`,
o.`links`,
o.`keywords`,
o.`status_id`,
o.`users_id`,
o.`date`,
o.`notes`,
o.`c_reason`,
o.`agent_star`
s.*
u.*
f.*
FROM `order` as o
LEFT JOIN `services` as s ON s.`id` = o.`service_id`
LEFT JOIN `users` as u ON u.`id` = o.`users_id`
LEFT JOIN `files` as f ON f.`order_id` = o.`id`