append mysql text to select from?

Hello everyone

Normally I use PHP with MySQL to query data from the DB and use PHP to add the appropriate unit, e.g. liters, grams, euros, etc.

Now I just have to make do with SQL.

How can I add this if I, for example,

select SP1, SP2 from mytable where ….

Thanks

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
3 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
verreisterNutzer
1 year ago

My old answer only goes to PostgresSQL, I did not read your question properly sorry. In MySQL you use the CONCAT function:

SELECT id, CONCAT(feld1, ' Liter')
FROM tabelle;

— Original answer —

If I understand it correctly, you want an issue like

| ID | Anzahl   |
|----|----------|
|  1 | 10 Liter |
|  2 | 20 Liter |

You can use a concatenation operator in the issue. That’s what it looks like.

SELECT id, feld1 || ' Liter'
FROM tabelle;
ultrarunner
1 year ago
SELECT CONCAT(SP1, ' Liter'), CONCAT(SP2, ' Gramm')
  FROM mytable WHERE ...