Introduction
We use quotes to tell the database where a text starts and ends. Concatenation joins pieces of text together to make one longer text.
SELECT 'text' AS example_text; -- Concatenate strings using || or CONCAT function SELECT 'Hello' || ' ' || 'World' AS greeting; -- Or using CONCAT function SELECT CONCAT('Hello', ' ', 'World') AS greeting;
SELECT 'apple' AS fruit;
SELECT 'Hello' || ' ' || 'World' AS greeting;
SELECT CONCAT('Good', ' ', 'Morning') AS greeting;
SELECT "column_name" FROM table_name;
SELECT 'John' AS first_name, 'Doe' AS last_name, 'Hello, ' || 'John' || ' ' || 'Doe' AS greeting, CONCAT('Hello, ', 'John', ' ', 'Doe') AS greeting_concat;
Hello?'Hello' and 'World'?|| to join strings. Some databases use CONCAT() function.+ which is not standard SQL for strings. SELECT 'Hello' || 'World'; uses || which is correct in standard SQL but not supported in all databases. SELECT CONCAT('Hello', 'World'); uses CONCAT() which is valid and widely supported in many databases. SELECT 'Hello' & 'World'; uses & which is invalid.SELECT 'SQL' || ' ' || 'Rocks' AS message;
|| joins strings without adding extra quotes in the output.SELECT "Hello" || 'World';
|| is standard but not supported everywhere; CONCAT() is widely supported.Pass the test and this pattern moves unknown