例子:

一表中的price_start_station_id and price_end_station_id 和二表中的 station_id 对应
pdo_fetchall('select 其他字段,b.station_name as station_name1,c.station_name as station_name2 from '.tablename('goupiao_price').' a
left join '.tablename('goupiao_station').'b on a.price_start_station_id =b.station_id
left join '.tablename('goupiao_station').'c on
or a.price_end_station_id=c.station_id ');
left join '.tablename('goupiao_station').'b on a.price_start_station_id =b.station_id
left join '.tablename('goupiao_station').'c on
or a.price_end_station_id=c.station_id ');
SQL联表查询示例
本文介绍了一种使用PHP PDO进行复杂SQL联表查询的方法,通过左连接将票价信息表与车站信息表关联,实现从票价表中获取起始站和终点站名称的功能。

被折叠的 条评论
为什么被折叠?



