SELECT
dealing_record.*
,shares.*
,transaction_type.*
FROM
shares
INNER JOIN shares ON shares.share_ID = dealing_record.share_id
INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id;
Run Code Online (Sandbox Code Playgroud)
上面的SQL代码产生了所需的输出,但有几个重复的列.此外,列标题显示不完整.当我改变了
linesize 100
Run Code Online (Sandbox Code Playgroud)
标题显示但数据显示重叠
我已经检查了类似的问题,但我似乎没有得到如何解决这个问题.
Alb*_*ano 10
您有重复的列,因为,您要向SQL引擎询问他们将向您显示相同数据(使用SELECT dealing_record.*等等)的列,然后重复.
例如,transaction_type.transaction_type_id列和dealing_record.transaction_type_id列将具有匹配的行(否则您将看不到任何内容INNER JOIN),您将看到这些重复项.
如果你想避免这个问题,或者至少要减少结果中重复的风险,那就改善你的查询,只使用你真正需要的列,就像@ConradFrix已经说过的那样.一个例子是这样的:
SELECT
dealing_record.Name
,shares.ID
,shares.Name
,transaction_type.Name
,transaction_type.ID
FROM
shares
INNER JOIN shares ON shares.share_ID = dealing_record.share_id
INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id;
Run Code Online (Sandbox Code Playgroud)