Jump to content

Recommended Posts

Posted

I imagine this should be fairly straight forward but I cant seem to find any examples of it to help me.

 

I have the following Postgre SQL query:

 

select field1, field2, field3, field4
from table
where field1 = 'text' 
and field4 is not null

 

Which works well, and displays the results in the format

 

Field1 | Field2 | Field3 | Field4

 

I am trying to concatenate Field2 and Field3 results so it will show the results as:

 

Field1 | Field2Field3 | Field4

 

What would the SQL query for this be please?

 

Many thanks

 

RB

Posted (edited)

Or you could try

 

SELECT     Field1, 
          Field2 + ' ' + Field3 AS [New Field Name for both columns], 
          Field4 
FROM table

 

Essentially I am just joining the two fields together and separating them with an empty string with a space.

 

If you don't want the space then it will just be Field2+Field3 as [New Field name]

Edited by Spl1t
  • Thanks 1
Posted

an example from the w3schools site combining the CONCAT and Alias options used in the above :

 

 

SELECT CustomerName, CONCAT(Address,', ',City,', ',PostalCode,', ',Country) AS Address

FROM Customers;

 

can be found at

 

SQL Aliases

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...