truthseeker
truthseeker

Reputation: 2265

Is there any natural join replacement in SQL Server 2005?

I have two tables which I would like to join by ID field. I was trying to use for this "INNER JOIN". Everything 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?

Upvotes: 0

Views: 671

Answers (2)

egrunin
egrunin

Reputation: 25073

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

Upvotes: 2

SQLMenace
SQLMenace

Reputation: 135061

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)

Upvotes: 5

Related Questions