57

I'm trying to understand the following query:
select count(distinct Name || '' || Surname) from PEOPLE;
What does the double bars mean? What does this query do?


In MySQL:
select "aaaaa" || '' || "bbbbb";

+--------------------------+ | "aaaaa" || '' || "bbbbb" | +--------------------------+ | 0 | +--------------------------+

zer0uno
  • 7,521
  • 13
  • 57
  • 86
  • 2
    In Oracle DB two vertical bars concat strings. What db are you using? – bsiamionau May 28 '14 at 18:39
  • 3
    This is string concatenation. You could run the query and see it for yourself. – Andrew Logvinov May 28 '14 at 18:39
  • When posting a question about SQL, it's usually relevant to also add a tag for the specific DBMS you're using, as syntax varies between them. (In this case, it appears you're using Oracle.) – Ken White May 28 '14 at 18:41
  • @zvdh I'm using MySQL, and It doesn't seem string concatenationg – zer0uno May 28 '14 at 18:41
  • 1
    @Martin: I know, but the DBMS is relevant quite often; it's a good habit to get into. SQL Server uses '+' as a string concatenation operator, for instance. (Of course, the better solution would have been for the poster to simply run the query without the `count()` to see what it did in the first place instead of posting here.) – Ken White May 28 '14 at 18:44
  • 3
    @Andreas, thank you, one of the answers says: `in MySQL || means 'logical or'` – bsiamionau May 28 '14 at 18:50

1 Answers1

60

double bars are concatination:

select 'hello' || ' ' || 'world' from dual;

yields

'hello world'
Andreas
  • 4,937
  • 2
  • 25
  • 35
  • 7
    Note you can also put a **column name** in the concat -- ```select 'hello' || col_1 || 'world' from dual;``` will concat the col_1 values from the table for the returned entries. – storm_m2138 Sep 19 '17 at 19:07
  • select 'hello' || ' ' || 'world' from dual; => 0 – Unkas Dec 08 '20 at 13:55
  • Note that this answer from the ansi standard. For `||`, mysql does not follow that standard. see https://stackoverflow.com/a/23372603/3430807 for details. – Andreas Jun 01 '21 at 17:11