
- 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 all the columns of a MySQL table to a particular value with a single query
Let us first create a table −
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(40), ClientAge int, ClientCountryName varchar(40) ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('Chris',25,'US'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('Bob',55,'UK'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ClientName,ClientAge,ClientCountryName) values('David',45,'AUS'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+------------+-----------+-------------------+ | 1 | Chris | 25 | US | | 2 | Bob | 55 | UK | | 3 | David | 45 | AUS | +----------+------------+-----------+-------------------+ 3 rows in set (0.00 sec)
Here is the query to set all the columns of a MySQL table to a particular value −
mysql> update DemoTable set ClientName='Sam',ClientAge=48,ClientCountryName='AUS' where ClientId=2; Query OK, 1 row affected (0.22 sec) Rows matched : 1 Changed : 1 Warnings : 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+------------+-----------+-------------------+ | 1 | Chris | 25 | US | | 2 | Sam | 48 | AUS | | 3 | David | 45 | AUS | +----------+------------+-----------+-------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Update two columns with a single MySQL query
- MySQL query to select all the records only from a specific column of a table with multiple columns
- How to set all values in a single column MySQL Query?
- Insert all the values in a table with a single MySQL query separating records by comma
- How to update all the entries except a single value in a particular column using MySQL?
- MySQL query to sort multiple columns together in a single query
- Concatenate all the columns in a single new column with MySQL
- Selecting a value in custom order from another column in a MySQL table with a single query
- Change multiple columns in a single MySQL query?
- A single MySQL query to insert records (not all) in the second table from the first table
- How to increment all the rows of a particular column by 1 in a single MySQL query (ID column +1)?
- Insert multiple values in a temporary table with a single MySQL query?
- Delete records from a MySQL table with IN() in a single query
- MySQL query to combine two columns in a single column?
- MySQL query to get the length of all columns and display the result in a single new column?

Advertisements