John John - 1 year ago 67
SQL Question

SQL SELECT statement with symbol or text

I am trying to get data from my database. I have no problems with this, the SELECT statement works fine, but I want to select the record with a symbor or text before the result.

When I run the code:

SELECT price
FROM products
WHERE id = "1"

Ill get
. But in this case I want to select it with a "€" symbol before the price. I found some scripts on this site where they are using the following code:

SELECT "€ " + price as 'price'
FROM products
WHERE id="1"

When I run this i get the same result as in the first code. So my question is: How can I select the
from the database with a symbol or text before (or after) the result?

Answer Source

Since you specified what is your RDBMs your answer is:

SELECT CONCAT('€ ', price) as price
  FROM products
 WHERE id=1

Don't use double quotes to use strings, double quotes on SQL is to name things like columns as alias and only use it when you want a field named with characters that the database wouldn't allow it like "Column name with spaces"

Also, ID is probably a number, so no need to use quotes since it will imply in implicit conversion which will make your query slower.