Search code examples
sqlpostgresqlinner-join

How to get all columns in PostgreSQL along with CONCATing two columns?


So i am joining these two tables A and B B contains first_name and last_name So i am writing query like this

select col1,col2,...,col12,CONCAT(first_name,last_name) as NAME 
from A 
  INNER JOIN B on A.email=B.email;

Now i want all columns from this query but instead of writing all column names...are there any ways to get every column along with concatenation of these two first_name and last_name?


Solution

  • Use *

    select *, CONCAT(first_name,last_name) as NAME 
    from A 
      INNER JOIN B on A.email=B.email;
    

    If you want to get the join column only once, you can use:

    select *, CONCAT(first_name,last_name) as NAME 
    from A 
      INNER JOIN B using (email);