18818181881
18818181881

Reputation: 95

concat in concat mysql

lets say i have a table like this

+-----+---------------+
| id  |     name      |
+-----+---------------+
|   1 | Meatball 300g |
+-----+---------------+

how do i made the url column with this format > myurl.com/id product/name (but separate with "-")

so based on expected results, it's should be like this

+-----+---------------+---------------------------+
| id  |     name      |            url            |
+-----+---------------+---------------------------+
|   1 | Meatball 300g | myurl.com/1/Meatball-300g |
+-----+---------------+---------------------------+

i try with this but dont have any idea with the concat inside concat

SELECT CONCAT_WS("/","myurl.com",id,CONCAT(dont know if this format concat was right)) AS url

Upvotes: 0

Views: 36

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520928

Use single quotes for string literals, and I think you want:

SELECT id, name, CONCAT_WS('/', 'myurl.com', id, REPLACE(name, ' ', '-')) AS url
FROM yourTable;

Upvotes: 2

Related Questions