bxx
bxx

Reputation: 1771

MySQL query result that use value of other fields

I'm looking for something like format() in other programming languages in MySQL query. The expected result is text that has values from other fields.

For example, something like

select formatted from table where formatted=stringformat('some text {0}, {1} some text.', field1, field2)

Upvotes: 2

Views: 74

Answers (2)

zaib shah
zaib shah

Reputation: 21

create a column in query and give it any alias to get result in. see this example.


SELECT ('some text, ' + tb.Col1 + ', ' + tb.Col2)    AS    ColName
FROM   MyTable   tb

Upvotes: 0

Galz
Galz

Reputation: 6842

how about:

SELECT CONCAT('some text ', field1, ', ', field2, ' some text.') FROM table;

Upvotes: 3

Related Questions