PDA

View Full Version : SQL Select and concatenating strings



mikeym
June 23rd, 2008, 03:55 PM
Hi,

Sorry this isn't really the place for this but I was wondering if anyone could tell me quickly how to concatenate strings together in an SQL statement like:



SELECT `page` + '#' + `section` AS 'url'
FROM `bbcode`

Which currently returns '0' for each field.

Keith Hedger
June 23rd, 2008, 04:05 PM
I think this is what u need
mysql> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql> SELECT CONCAT(14.3);
-> '14.3'

u might want to install the docs for my sql via synaptic (mysql-doc-5.0)

CptPicard
June 23rd, 2008, 04:12 PM
The standard string concatenation operator in SQL is ||. Like 'Add this' || ' to this'.

henchman
June 23rd, 2008, 05:14 PM
There's an useful overview of mysql's string manipulation functions (including CONCAT and CONCAT_WS) here:

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

CptPicard
June 23rd, 2008, 09:24 PM
The OP isn't saying anything about MySQL... there are other SQL databases you know :)

henchman
June 23rd, 2008, 10:04 PM
Sorry... sql seem to be automatically mysql for me...:(

Keith Hedger
June 24th, 2008, 11:00 AM
yeah same here but isn't the basic syntax on sql standard?

CptPicard
June 24th, 2008, 07:56 PM
yeah same here but isn't the basic syntax on sql standard?

Yes. That's why he should be using the standard '||' (IIRC) instead of nonstandard mysql functions :)