
- 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
How to set all values in a single column MySQL Query?
To set all values in a single column MySQL query, you can use UPDATE command.
The syntax is as follows.
update yourTableName set yourColumnName =yourValue;
To understand the above syntax, let us create a table. The query to create a table is as follows.
mysql> create table setAllValuesDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Amount int -> ); Query OK, 0 rows affected (0.64 sec)
Now you can insert some records in the table using insert command.
The query is as follows.
mysql> insert into setAllValuesDemo(Name,Amount) values('John',2345); Query OK, 1 row affected (0.22 sec) mysql> insert into setAllValuesDemo(Name,Amount) values('Carol',47586); Query OK, 1 row affected (0.13 sec) mysql> insert into setAllValuesDemo(Name,Amount) values('Bob',95686); Query OK, 1 row affected (0.15 sec) mysql> insert into setAllValuesDemo(Name,Amount) values('David',95667); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement.
The query is as follows.
mysql> select *from setAllValuesDemo;
The following is the output.
+----+-------+--------+ | Id | Name | Amount | +----+-------+--------+ | 1 | John | 2345 | | 2 | Carol | 47586 | | 3 | Bob | 95686 | | 4 | David | 95667 | +----+-------+--------+ 4 rows in set (0.00 sec)
Here is the query to set all values in a single column MySQL query.
mysql> update setAllValuesDemo set Amount=10500; Query OK, 4 rows affected (0.20 sec) Rows matched: 4 Changed: 4 Warnings: 0
Now check the table records once again using select statement.
The query is as follows.
mysql> select *from setAllValuesDemo;
The following is the output.
+----+-------+--------+ | Id | Name | Amount | +----+-------+--------+ | 1 | John | 10500 | | 2 | Carol | 10500 | | 3 | Bob | 10500 | | 4 | David | 10500 | +----+-------+--------+ 4 rows in set (0.00 sec)
- Related Articles
- How to concatenate all values of a single column in MySQL?
- Set 'alias' for all the column names in a single MySQL query
- How to use a single MySQL query to count column values ignoring null?
- How do I insert multiple values in a column with a single MySQL query?
- A single MySQL query to search multiple words from different column values
- MySQL query to set current date in the datetime field for all the column values
- Get multiple count in a single MySQL query for specific column values
- Make all column names lower case in MySQL with a single query
- How to add column and index in a single MySQL query?
- How to increment all the rows of a particular column by 1 in a single MySQL query (ID column +1)?
- MySQL query to combine two columns in a single column?
- MySQL query to get the character length for all the values in a column?
- Copy values of one column to another using INSERT and SELECT in a single MySQL query
- MySQL query to return all items in a single row
- Display all the column values in a single row separated by comma in MySQL?

Advertisements