skip to Main Content

How to add space between two name columns concatenated in SQL ?

SELECT CONCAT(a.first_name, a.last_name), f.title, f.description, f.length
FROM actor a
JOIN film_actor fa
ON a.actor_id = fa.actor_id
JOIN film f
ON f.film_id = fa.film_id

snapshot of result of query

i want to have space between names like "PenelopeGuiness" to "Penelope Guiness"

3

Answers


  1. Chosen as BEST ANSWER

    I tried to add ' ' inside CONCATE parameters but id did not work! Anyway, I just found below solution and it worked.

    SELECT a.first_name || ' ' || a.last_name AS full_name
    

  2. SELECT CONCAT(a.first_name, " ", a.last_name), f.title, f.description, f.length
    FROM actor a
    JOIN film_actor fa
    ON a.actor_id = fa.actor_id
    JOIN film f
    ON f.film_id = fa.film_id
    
    Login or Signup to reply.
  3. Each of these concatenates a space character in between:

    first_name || ' ' || last_name
    concat(first_name, ' ', last_name)
    concat_ws(' ', first_name, last_name)
    

    (The first form with basic concatenation operator being very slightly cheaper.)

    But each form handles NULL input differently. You typically want "NULL-safe" concatenation with concat_ws() if that can happen. Detailed assessment:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search