
- 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
Set multiple values for custom columns in MySQL?
For this, you can use UNION ALL. Let us first create a table −
mysql> create table DemoTable1987 ( UserValue int ); Query OK, 0 rows affected (2.90 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1987 values(4); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1987 values(5); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1987 values(6); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1987 values(7); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1987;
This will produce the following output −
+-----------+ | UserValue | +-----------+ | 4 | | 5 | | 6 | | 7 | +-----------+ 4 rows in set (0.00 sec)
Here is the query to set multiple values for custom columns −
mysql> select UserValue,(UserValue*100) as NewValue from DemoTable1987 union all select UserValue,(UserValue*50) as NewValue from DemoTable1987 order by UserValue;
This will produce the following output −
+-----------+----------+ | UserValue | NewValue | +-----------+----------+ | 4 | 400 | | 4 | 200 | | 5 | 500 | | 5 | 250 | | 6 | 300 | | 6 | 600 | | 7 | 350 | | 7 | 700 | +-----------+----------+ 8 rows in set (0.14 sec)
- Related Articles
- Set custom messages for enum values in MySQL
- Set a custom value for NULL or empty values in MySQL
- Display only the default values set for columns in MySQL
- Set DEFAULT values for columns while creating a table in MySQL
- Set conditions for columns with values 0 or 1 in MySQL
- Count value for multiple columns in MySQL?\n
- MySQL Select Statement DISTINCT for Multiple Columns?
- MySQL query to display custom text for empty columns
- Conditional WHERE clause in MySQL stored procedure to set a custom value for NULL values
- Searching multiple columns for a row match in MySQL
- Populate null columns in a MySQL table and set values
- MySQL multiple COUNT with multiple columns?
- Set ENUM in MySQL for column values
- Custom sorting using two different columns in MySQL?
- How to check multiple columns for a single value in MySQL?

Advertisements