What does SQL Select symbol || mean?

MysqlSqlOracleAnsi Sql

Mysql Problem Overview


What does || do in SQL?

SELECT 'a' || ',' || 'b' AS letter

Mysql Solutions


Solution 1 - Mysql

|| represents string concatenation. Unfortunately, string concatenation is not completely portable across all sql dialects:

  • ansi sql: || (infix operator)
  • mysql: concat ( vararg function ). caution: || means 'logical or' (It's configurable, however; thanks to @hvd for pointing that out)
  • oracle: || (infix operator), concat ( caution: function of arity 2 only ! )
  • postgres: || (infix operator)
  • sql server: + (infix operator), concat ( vararg function )
  • sqlite: || (infix operator)

hopefully the confusion is complete ...

Solution 2 - Mysql

It is a concat statement. It will concatenate the two strings.

Here is a helpful post!

https://stackoverflow.com/questions/11403931/what-is-the-difference-between-operator-and-concat-function-in-oracle

Solution 3 - Mysql

SELECT 'a' || ',' || 'b' AS letter will combine a letter. The result become 'a,b'

Solution 4 - Mysql

It's a concatenation operator. So you would get 'a,b' from that. I think || will work on most RDBMS's. SQL Server requires the + operator (thanks to HVD for setting me straight!).

Solution 5 - Mysql

In Oracle, SQLite3, and MySQL, it concatenates strings. Please see the Oracle documentation. The MySQL documentation.

Also, it's part of ANSI SQL, but read this for more information.

Solution 6 - Mysql

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3586553View Question on Stackoverflow
Solution 1 - MysqlcollapsarView Answer on Stackoverflow
Solution 2 - MysqlJohn HartsockView Answer on Stackoverflow
Solution 3 - MysqlivanprakasaView Answer on Stackoverflow
Solution 4 - MysqlAndrewView Answer on Stackoverflow
Solution 5 - MysqlSQLMasonView Answer on Stackoverflow
Solution 6 - MysqlJonathanView Answer on Stackoverflow