0

I have a simple sql:

select select t.x, '%' || t.x || '%' as c from t

The result is:

x c
a 0
b 0

That is, the catenatation results in 0, I don't know why

Tom
  • 5,848
  • 12
  • 44
  • 104
  • @TrebuchetMS `||` is ansi-standard. [See here.](https://stackoverflow.com/a/24777235/3094533) – Zohar Peled Dec 25 '18 at 12:52
  • @TrebuchetMS thanks for the reply. It is not duplicate of the link you mentioned,they are different question. concat() works for me, || is also mysql syntax, but doesn't work for %, don't know why – Tom Dec 25 '18 at 12:52
  • 1
    Possible duplicate of [What does double bars (||) mean in SQL?](https://stackoverflow.com/questions/23919378/what-does-double-bars-mean-in-sql) – trincot Dec 25 '18 at 12:54
  • @ZoharPeled my bad, wasn't aware that `||` could work with MySQL as well. – TrebledJ Dec 25 '18 at 12:54
  • 3
    https://stackoverflow.com/a/23372603/5459839: in MySql, `||` is not (by default) string concatenation, but a logical OR. – trincot Dec 25 '18 at 12:56
  • Thanks all the guys for the reply, not aware of this before. – Tom Dec 25 '18 at 12:59
  • 1
    Because MySQL is the PHP of databases. A bit weird, but it's free, so everybody uses it anyway. :-p – GolezTrol Dec 25 '18 at 13:03

0 Answers0