开发者

Is there any natural join replacement in SQL Server 2005?

开发者 https://www.devze.com 2022-12-31 16:00 出处:网络
I have two tables which I would like to join by ID field. I was trying to use for this \"INNER JOIN\". Ev开发者_如何学Goerything would be good but there are two issues:

I have two tables which I would like to join by ID field. I was trying to use for this "INNER JOIN". Ev开发者_如何学Goerything would be good but there are two issues:

  1. As a result I receive twice column ID.
  2. I have to omit specifying columns which should be displayed under select statement. I would like to use there a *.

I red that other sql-s have something like natural join and that is probably (or not?) an answer for my question. Unfortunately there is no join like that in SQL Server (2005). Do anybody knows any good replacement of it?


SQL Server does not have the natural join, just list out all the columns you want. (you can drag the table column folder in SSMS to the code window and all the columns for the table will be listed, then you just delete the ones you don't want)


I think you want

SELECT * FROM x INNER JOIN y ON x.id = y.id

But you want to skip y.id (because it duplicates x.id).

If this is correct: no, there's no way to do this in any dialect of SQL I know. You'll have to say

SELECT x.*, y.col1, y.col2, ... FROM x INNER JOIN y ON x.id = y.id
0

精彩评论

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