开发者

Handling Ambiguous Column Names

Im in a position where I cannot alter the table structure of my database and I have Ambiguous Column Names in [table1] and [table2]. I do not need to use any fields from [table2] but its existence is necessary to relate to another table. Is there a w开发者_高级运维ay that I handle this?


Every time you refer to one of the ambiguous column names you should specify the table name or alias.

SELECT ...
FROM [table1]
JOIN [table2]
ON [table1].ambiguous_column = [table2].ambiguous_column
AND ...


use table aliases

SELECT A.* 
FROM TABLE_A A
JOIN TABLE_B B ON A.ID = B.ID
ORDER BY A.FIELD


use the SQL statement AS to create uniquel names

SELECT 
  A.feld1  AS F1,
  A.feld2  AS F2,
  B.feld1  AS F3
FROM table1 AS A
JOIN table2 AS B ON A.id = B.id
ORDER BY A.field1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜