[英]MySQL - Rename selected columns with the same name from two different tables
[英]Output from two tables that has two same name columns
我确实有一个MySQL脚本,该脚本使用INNER JOIN将两个表放在一起。 这两个表都有一个称为ID的字段。 我确实需要用PHP输出两个ID字段。 我该怎么做呢?
这是我的脚本:
$sql = "SELECT a.id,
a.route_id,
a.requester,
a.reservation,
a.reservation_date,
a.reservation_by,
a.telephone,
a.email,
a.firstname,
a.lastname,
a.qty_pax,
a.date_trip,
a.time_trip,
a.trip_type,
a.cancelled,
a.notes,
a.room,
a.driver_id,
b.id,
b.dep_symbol,
b.dep_location_id
FROM
general_reservations a
INNER JOIN
routes b
WHERE
a.cancelled<>'2'
AND a.date_trip BETWEEN '$find_begin' AND '$find_end'
AND b.dep_symbol LIKE '$code'
AND b.id LIKE a.route_id
ORDER BY a.date_trip, b.dep_symbol, a.route_id";
注意,我确实有两个不同表的a.id和b.id。
使用别名 ,
$sql = "SELECT a.id AS aid,
a.route_id,
a.requester,
a.reservation,
a.reservation_date,
a.reservation_by,
a.telephone,
a.email,
a.firstname,
a.lastname,
a.qty_pax,
a.date_trip,
a.time_trip,
a.trip_type,
a.cancelled,
a.notes,
a.room,
a.driver_id,
b.id AS bid,
b.dep_symbol,
b.dep_location_id
FROM
general_reservations a
INNER JOIN
routes b
WHERE
a.cancelled<>'2'
AND a.date_trip BETWEEN '$find_begin' AND '$find_end'
AND b.dep_symbol LIKE '$code'
AND b.id LIKE a.route_id
ORDER BY a.date_trip, b.dep_symbol, a.route_id";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.