
- 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 a specific value for the first three column values in MySQL?
To set a specific value for only 1st three values, you need to use LIMIT 3. Let us first create a table −
mysql> create table DemoTable1968 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1968(Name) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Sam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1968(Name) values('Carol'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1968;
This will produce the following output −
+----+-------+ | Id | Name | +----+-------+ | 1 | Chris | | 2 | David | | 3 | Sam | | 4 | Mike | | 5 | Carol | +----+-------+ 5 rows in set (0.00 sec)
Here is the query to set a specific value for the first three column values −
mysql> update DemoTable1968 set Name='Robert' order by Id limit 3; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again:
mysql> select * from DemoTable1968;
This will produce the following output −
+----+--------+ | Id | Name | +----+--------+ | 1 | Robert | | 2 | Robert | | 3 | Robert | | 4 | Mike | | 5 | Carol | +----+--------+ 5 rows in set (0.00 sec)
- Related Articles
- Place a specific value for NULL values in a MySQL column
- Select a specific value between two column values in MySQL?
- Fix a specific column value and display random values for rest of the rows in MySQL
- Set ENUM in MySQL for column values
- Getting maximum from a column value and set it for all other values in the same column with MySQL?
- Swap a specific column value in MySQL
- Get multiple count in a single MySQL query for specific column values
- MySQL query to find the average of only first three values from a column with five values
- Set value only for NULL values in a MySQL table
- How do I set the default value for a column in MySQL?
- Fetch a specific column value (name) in MySQL
- Set a custom value for NULL or empty values in MySQL
- Compare for NULL value and display value 1 for these values in a new MySQL column?
- Replace only a specific value from a column in MySQL
- ORDER BY specific field value first in MySQL

Advertisements