Is there a way to rename columns with the same name from two tables when making a join?

I have two tables to which I join the following query ...

select * 
  from Partners p 
inner join OrganizationMembers om on p.ParID = om.OrganizationId 
where om.EmailAddress = 'my_email@address.com' 
  and om.deleted = 0

Which works fine, but some of the columns from PartnersI want to replace the columns with the same name from OrganizationMembers. The number of columns that I want to replace in the joined table is very small, should not be more than 3.

You can get the result that I want by selectively selecting the columns that I want in the resulting join, for example ...

select om.MemberID, 
       p.ParID, 
       p.Levelz, 
       p.encryptedSecureToken, 
       p.PartnerGroupName, 
       om.EmailAddress, 
       om.FirstName, 
       om.LastName 
 from Partners p 
inner join OrganizationMembers om on p.ParID = om.OrganizationId 
     where om.EmailAddress = 'my_email@address.com' 
       and om.deleted = 0

But this creates a very long sequence select p.a, p.b, p.c, p.d, ... etc ..., which I am trying to avoid.

Partners 3 OrganizationMembers, . ?

+3
4

.

, , * - , DBA.

-, , "-" - .

SELECT p.*, om.MemberId, etc..

, , .

+2
select om.MemberID as mem

AS. .

+3

:

p.*,
om.EmailAddress, 
om.FirstName, 
om.LastName 

*. , , .

+2

p.a, p.b, p.c, p.d,... ..... .

. !

, .

  • , .
  • , .
  • Adding a column to the table will not automatically change the behavior of your query.
  • Removing a column from the table will ruin your query earlier, which will lead to errors being closer to the source and easier to find and fix.

And everything that uses the query will still have to list all the columns, so it makes no sense to be lazy about it!

+2
source

Source: https://habr.com/ru/post/1736343/


All Articles