

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add a temporary column with a value in MySQL?
You can add a temporary column with value with the help of the following syntax −
select yourColumnName1,yourColumnName2,.....N ,yourTemporaryColumnValue as yourTemporaryColumnName from yourTableName;
To add a temporary column with a value, let us create a table. The following is the query −
mysql> create table TemporaryColumnWithValueDemo −> ( −> StudentId int, −> StudentName varchar(100) −> ); Query OK, 0 rows affected (0.59 sec)
Inserting some records in the table. The query to insert records are as follows −
mysql> insert into TemporaryColumnWithValueDemo values(101,'John'); Query OK, 1 row affected (0.13 sec) mysql> insert into TemporaryColumnWithValueDemo values(102,'Johnson'); Query OK, 1 row affected (0.15 sec) mysql> insert into TemporaryColumnWithValueDemo values(103,'Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into TemporaryColumnWithValueDemo values(104,'Sam'); Query OK, 1 row affected (0.16 sec)
Display all records inserted above. The query to display all records is as follows −
mysql> select *from TemporaryColumnWithValueDemo;
The following is the output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 101 | John | | 102 | Johnson | | 103 | Carol | | 104 | Sam | +-----------+-------------+ 4 rows in set (0.00 sec)
Now here is the query to add a column with a t.emporary value. The query is as follows −
mysql> select StudentId,StudentName,'M.I.T.' as TempCollegeName from TemporaryColumnWithValueDemo;
The following is the output. The temporary column added successfully −
+-----------+-------------+-----------------+ | StudentId | StudentName | TempCollegeName | +-----------+-------------+-----------------+ | 101 | John | M.I.T. | | 102 | Johnson | M.I.T. | | 103 | Carol | M.I.T. | | 104 | Sam | M.I.T. | +-----------+-------------+-----------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- Add a temporary column in MySQL where the values depend on another column?
- Add an autoincrement column with a custom start value in MySQL
- Add user defined value to a column in a MySQL query?
- Create a temporary table with dates in MySQL
- Performing total of a column in a temporary column in SAP
- Add a new value to a column of data type enum in MySQL?
- Increment column value ‘ADD’ with MySQL SET clause
- MySQL SELECT to sum a column value with previous value
- Order randomly in MySQL with a random value column?
- Python - Add a new column with constant value to Pandas DataFrame
- MySQL SELECT to add a new column to a query and give it a value?
- Create a temporary table in a MySQL procedure?
- Add leading zeros to a MySQL column?
- Insert multiple values in a temporary table with a single MySQL query?
- MySQL query to remove a value with only numbers in a column
Advertisements