1

I have database table which contains two columns "url" of type varchar and "www" of type tinyint which contains 1, if url was specified with www prefix, and 0, if not.

I want create a column in mysql view called full url which would contain following equivalent of c++ code:

full_url = "http://" + (www == 1 ? "www." : "") + url;

Can you help me?

2 Answers 2

2
SELECT CONCAT('http://', IF(www = 1, 'www.', ''), url) AS full_url FROM table
Sign up to request clarification or add additional context in comments.

Comments

0

You can use CASE

SELECT
(CASE WHEN www == 0 /*if not specified with www then add www*/
THEN CONCAT('http://','www.',url) 
ELSE CONCAT('http://',url) /*url contains www*/
END ) `url`
FROM ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.