prestarocket
prestarocket

Reputation: 753

mysql : create virtual column et set defaut value

I have this mysql query :

Select name from my_table

This query return me this result :

 NAME
-------
 name1
 name2
 name3

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

 NAME   | Virtual Column
------------------------  
 name1  |    defaut_value
 name2  |    defaut_value
 name3  |    defaut_value

Upvotes: 4

Views: 6752

Answers (1)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79969

Like this:

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

This is legal this way, because in the SELECT clause you can select what so called, in the SQL standard, a value expression. Where value expression can be either of the following1:

enter image description here


1: This image from: SQL Queries for Mere Mortals(R): A Hands-On Guide to Data Manipulation in SQL

Upvotes: 9

Related Questions