我有两张桌子,
管理员,定价
我想做一个连接两个表的选择,其中pricing.relation = admin.id
如何重命名value,id和date_created行,使它们不会相互覆盖?
这是我正在尝试的事情:
$sub_types = $database->query('
SELECT
pricing.*,
admin.*
FROM
pricing,
admin
WHERE pricing.relation = admin.id
');
答案 0 :(得分:9)
您可以使用别名:
SELECT p.id as pid,
p.date_created as pricing_date,
p.type, p.value as pricing_value,
a.id as aid,
a.date_created as admin_date,
a.relation,
a.value as admin_value
FROM pricing p
inner join admin a on p.relation = a.id