5

我有2张桌子,

管理员,定价

  • admin 包含列(id、date_created、type、value)
  • 定价包含列(id、date_created、relation、value)

我想做一个连接两个表的选择,其中pricing.relation = admin.id

如何重命名值、id 和 date_created 行,以免它们相互覆盖?

这是我正在尝试的事情:

$sub_types = $database->query('
    SELECT 
    pricing.*,
    admin.*
        FROM 
        pricing,
        admin
            WHERE pricing.relation = admin.id
');
4

1 回答 1

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
于 2012-10-12T11:47:51.000 回答