
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- Add a temporary column in MySQL where the values depend on another column?
- Add an autoincrement column with a custom start value in MySQL
- Increment column value ‘ADD’ with MySQL SET clause
- Add user defined value to a column in a MySQL query?
- Add a new value to a column of data type enum in MySQL?
- Create a temporary table with dates in MySQL
- Order randomly in MySQL with a random value column?
- MySQL SELECT to sum a column value with previous value
- Performing total of a column in a temporary column in SAP
- 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?
- MySQL query to remove a value with only numbers in a column
- Add a character in the end to column values with MySQL SELECT?
- How to add time in a MySQL column set with type DATETIME?
- Update column data without using temporary tables in MySQL?

Advertisements