Mysql: create virtual column and set defaut value

I have this mysql query:

Select name from my_table 

This query returns me this result:

  NAME ------- name1 name2 name3 

How to create a virtual column and set the defaut value in this column? I want this result:

  NAME | Virtual Column ------------------------ name1 | defaut_value name2 | defaut_value name3 | defaut_value 
+4
source share
1 answer

Like this:

 SELECT name, 'default_value' AS "A Virtual Column" FROM my_table 

This is legal because in the SELECT you can select the so-called value expression in the SQL standard. Where the expression of value may be any of the following 1 :

enter image description here


1: This image is from: SQL Queries for Mortals (R): A Practical Guide to Manipulating Data in SQL

+9
source

Source: https://habr.com/ru/post/1389640/


All Articles