我希望用现有列名覆盖表中的列名。 我正在寻找一种方法来获取表中剩余的未指定列。
注意: 该查询将来可能会有更多的连接。
例如
人
+-----------+----------+---------+
| firstname | lastname | pers_id |
+-----------+----------+---------+
| Joe | Soap | 1 |
| Bobby | Pin | 2 |
| Janet | Jackson | 3 |
+-----------+----------+---------+
分类
+----------+-------------------+--------+
| type | description | cat_id |
+----------+-------------------+--------+
| customer | people who pay us | 1 |
| employee | people we pay | 2 |
| director | people who direct | 3 |
+----------+-------------------+--------+
Person_Cat (= ^ェ^ =)
+---------+--------+
| pers_id | cat_id |
+---------+--------+
| 3 | 1 |
| 2 | 2 |
| 1 | 3 |
+---------+--------+
查询
SELECT *, CONCAT(p.firstname, ' '
, p.lastname) as full_name
, c.cat_id AS category_id
, p.pers_id AS cat_id
FROM Person AS p
JOIN Person_Cat AS pc ON(p.pers_id = pc.pers_id)
JOIN Category AS c ON (pc.cat_id = c.cat_id)
输出 (道歉的长度,但后面的表格更重要)
+-----------+----------+---------+---------+--------+----------+-------------------+--------+---------------+-------------+--------+
| p | p | p | pc | pc | c | c | c | Select | Select | Select |
+-----------+----------+---------+---------+--------+----------+-------------------+--------+---------------+-------------+--------+
| firstname | lastname | pers_id | pers_id | cat_id | type | description | cat_id | full_name | category_id | cat_id |
+-----------+----------+---------+---------+--------+----------+-------------------+--------+---------------+-------------+--------+
| Janet | Jackson | 3 | 3 | 1 | customer | people who pay us | 1 | Janet jackson | 1 | 3 |
| Bobby | Pin | 2 | 2 | 2 | employee | people who we pay | 2 | Bobby Pin | 2 | 2 |
| Joe | Soap | 1 | 1 | 3 | director | people who direct | 3 | Joe Soap | 3 | 1 |
+-----------+----------+---------+---------+--------+----------+-------------------+--------+---------------+-------------+--------+
列名称上方的标题可供参考 到他们来自哪里。
列摘要 -
firstname
,lastname
,pers_id
,pers_id
,cat_id
,type
,
description
,cat_id
,full_name
,category_id
,cat_id
通缉输出
+-----------+----------+---------+--------+----------+-------------------+---------------+-------------+--------+
| p | p | pc | pc | c | c | Select | Select | Select |
+-----------+----------+---------+--------+----------+-------------------+---------------+-------------+--------+
| firstname | lastname | pers_id | cat_id | type | description | full_name | category_id | cat_id |
+-----------+----------+---------+--------+----------+-------------------+---------------+-------------+--------+
| Janet | Jackson | 3 | 1 | customer | people who pay us | Janet jackson | 1 | 3 |
| Bobby | Pin | 2 | 2 | employee | people who we pay | Bobby Pin | 2 | 2 |
| Joe | Soap | 1 | 3 | director | people who direct | Joe Soap | 3 | 1 |
+-----------+----------+---------+--------+----------+-------------------+---------------+-------------+--------+
列摘要 -
firstname
,lastname
,pers_id
,cat_id
,type
,
description
,full_name
,category_id
,cat_id
注意:
p.pers_id
和c.cat_id
不存在。我想这是因为与ConCat中使用的first
和lastname
不同,它们被直接调用并且未被修改
答案 0 :(得分:1)
如果简短回答是目前没有Select [remaining columns]
这样的概念(2015-06-17),如果您想使用SELECT *
但只删除多余的列< / strong>下,
然后,您需要在渲染视图时显式删除(忽略)这些冗余列。
您必须显式配置要忽略哪些列的逻辑,这与显式列出您感兴趣的列几乎相同,因此您将回到参数,而不是选择我在以上评论。
除非您的表架构一直在更改,否则实际上没有理由这样做。