我有以下查询:
SELECT sa.*, d.day, TIME_FORMAT(timefrom.time, '%H:%i') AS time_from, TIME_FORMAT(timeto.time, '%H:%i') AS time_to
FROM staff s
INNER JOIN staff_availability sa
ON sa.staff_id = s.staff_id
INNER JOIN days d
ON d.day_id = sa.day_id
LEFT JOIN time_slots AS timefrom
ON timefrom.time_slot_id = sa.time_from
LEFT JOIN time_slots AS timeto
ON timeto.time_slot_id = sa.time_to
INNER JOIN users u
ON s.user_id = u.user_id
WHERE u.user_id = :user_id
我使用别名time_from和time_to作为time_slots表中选择的格式化时间,这些时间与staff_availability表连接在一起。
查询返回以下内容:
staff_availability_id staff_id day_id time_from(join) time_to(join) day time_from (alias) time_to (alias)
有什么方法可以从结果中排除连接列?
答案 0 :(得分:1)
你必须手动选择它们。
更改此
SELECT sa.*
到
SELECT sa.staff_availability_id , sa.staff_id,....--what ever you want to select and dont select those you mentioned
答案 1 :(得分:0)
选择列,
SELECT sa.staff_availability_id ,sa.staff_id,d.day, TIME_FORMAT(timefrom.time, '%H:%i') AS time_from, TIME_FORMAT(timeto.time, '%H:%i') AS time_to
FROM staff s
INNER JOIN staff_availability sa
ON sa.staff_id = s.staff_id
INNER JOIN days d
ON d.day_id = sa.day_id
LEFT JOIN time_slots AS timefrom
ON timefrom.time_slot_id = sa.time_from
LEFT JOIN time_slots AS timeto
ON timeto.time_slot_id = sa.time_to
INNER JOIN users u
ON s.user_id = u.user_id
WHERE u.user_id = :user_id